import echarts from 'echarts/lib/echarts'
export default {
data() {
return {
}
},
props:['userpieData'],
watch: {
userpieData: function(newValue,oldValue) {
this.createE()
},
deep: true
},
methods:{
createE:function() {
console.log(this.userpieData)
var myChart = echarts.init(document.getElementById("myChart"));
myChart.setOption({
title: {
text: "用户分布",
x: "center"
},
tooltip: {
trigger: "item",
formatter: "{a}
{b} : {c} ({d}%)"
},
legend: {
orient: "vertical",
left: "left",
data: ["北京", "上海", "深圳", "杭州", "其他"]
},
series: [
{
name: "访问来源",
type: "pie",
radius: "55%",
center: ["50%", "60%"],
data: [
{ value: this.userpieData.beijing, name: "北京" },
{ value: this.userpieData.shanghai, name: "上海" },
{ value: this.userpieData.shenzhen, name: "深圳" },
{ value: this.userpieData.hangzhou, name: "杭州" },
{ value: this.userpieData.qita, name: "其他" }
],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: "rgba(0, 0, 0, 0.5)"
}
}
}
]
});
}
}
}
注意可以在watch中利用deep属性然后调用我的方法