百度了老多没啥能用的,完成需求之后晒到网上来吧,能帮助一个是一个别再着急挠头了
下面展示一些 内联代码片
。
<template>
<div :class="className" :style="{ height: height, width: width }" />
</template>
<script>
import echarts from "echarts"; //引入
require("echarts/theme/macarons"); // echarts theme
import { aaa } from ""; //接口
export default {
props: {
className: {
type: String,
default: "chart"
},
width: {
type: String,
default: "100%"
},
height: {
type: String,
default: "300px"
}
},
data() {
return {
chart: null,
processed: null, //从我接口取到的数据 处理
untreated: null //从我接口取到的数据 未处理
};
},
created() {},
mounted() {
this.call();
},
beforeDestroy() {
if (!this.chart) {
return;
}
this.chart.dispose();
this.chart = null;
},
methods: {
call() {
//下面是接口取数据方式
aaa().then(data => {
//数据保存到data中
this.processed = data.data[1];
this.untreated = data.data[2];
this.$nextTick(() => {
this.initChart();
});
});
},
initChart() {
this.chart = echarts.init(this.$el, "macarons");
collectionCount(3, 1).then(response => {
var xdata, ydata;
var str = "",
str2 = "";
response.data.forEach(function(e) {
str += e.createTime + ",";
str2 += e.num + ",";
});
str = str.substring(0, str.length - 1);
str2 = str2.substring(0, str2.length - 1);
this.newArr = str.split(",");
this.newArr2 = str2.split(",");
// console.log(this.newArr)
xdata = this.newArr;
ydata = this.newArr2;
// console.log(xdata)
this.chart.setOption({
title: {
text: "报警总数量饼状图",
left: "center"
},
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
legend: {
orient: "vertical",
left: "left",
data: ["已处理", "未处理"]
},
series: [
{
name: "访问来源",
type: "pie",
radius: "55%",
center: ["50%", "60%"],
data: [
{
value: this.processed == 0 ? null : this.processed,
name: "已处理"
},
{
value: this.untreated == 0 ? null : this.untreated,
name: "未处理"
}
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: "rgba(0, 0, 0, 0.5)"
}
}
}
]
});
});
}
}
};
</script>
多了些数据也是可以实现的
完结撒花,写的比较一般,不喜勿愤嘻嘻^^