javascript
//由于前后端交互,所以使用axios发送请求
const Count = ref(null); //设备种类数值
const Name = ref(null); //设备种类名称
//设备种类 饼图
const pieChart = () => {
const getpieChart = echarts.init(document.getElementById("deviceKind"));
// 创建图标
getpieChart.setOption({
tooltip: {
trigger: "item",
},
legend: {
top: "25%",
right: "right",
textStyle: {
color: "rgba(217,215,218,1.000)",
},
},
series: [
{
name: "Access From",
type: "pie",
radius: ["40%", "70%"],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 10,
borderColor: "#fff",
borderWidth: 2,
},
label: {
show: false,
position: "center",
},
emphasis: {
label: {
show: true,
fontSize: "40",
fontWeight: "bold",
},
},
labelLine: {
show: false,
},
data: null,
},
],
});
//echarts异步加载,获取后端数据
CenterOverviewType().then((res) => {
if (res.status === 200) {
//将二维数组拆分
Count.value = res.data.data.deviceTypeCount;
Name.value = res.data.data.deviceTypeName;
for (const key in Count.value) {
deviceChartsData.push({
name: Name.value[key],
value: Count.value[key],
});
}
//饼图重新赋值data
getpieChart.setOption({
series: [
{
data: deviceChartsData, //赋值
},
],
});
}
});
};
上一篇文章,