出现的问题是当不异步获取数据时,其颜色可以正常显示,部分代码及效果如下:
setOptions({ expectedData, actualData } = {}) {
this.chart.setOption({
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
visualMap: {
show: false,
min: 80,
max: 600,
inRange: {
colorLightness: [0, 1]
}
},
series: [
{
name: "访问来源",
type: "pie",
radius: "85%",
center: ["50%", "45%"],
data: [
{ value: 335, name: "钢混" },
{ value: 310, name: "砖混" },
{ value: 274, name: "水泥" },
{ value: 235, name: "钢筋" }
].sort(function(a, b) {
return a.value - b.value;
}),
roseType: "angle",
label: {
normal: {}
},
labelLine: {
normal: {
smooth: 0.2,
length: 10,
length2: 20
}
}
}
],
animationDuration: 2800,
animationEasing: "cubicInOut"
});
},
但是当异步获取了数据并绑定时,饼图变成了全黑色,不知道原因是什么,我的异步设置代码和最后效果如下,其中getData方法的调用也附在下面:
mounted() {
this.initChart();
this.getData();
if (this.autoResize) {
this.__resizeHanlder = _.debounce(() => {
if (this.chart) {
this.chart.resize();
}
}, 100);
window.addEventListener("resize", this.__resizeHanlder);
}
},
// getData方法
getData() {
let params = {
paramTypeId: 1
};
this.chart.showLoading();
getHouseParamCount(params).then(res => {
console.log(res.data.data)
this.chart.setOption({
series: {
data: res.data.data.content
}
});
this.chart.hideLoading();
});
},
发现问题好像是echart的原因,当换了一个示例时可以正常显示颜色了