1.在HTML中的代码:
<div id="echartZB" style="width:400px;height:600px;margin-left:50px"></div>
在js中的代码块:
initChart5(){
var myChart2 = echarts.init(document.getElementById('echartZB'))
myChart2.setOption({
title : {
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.closeTimeTX, name:'关机',itemStyle:{color:"black"}},
{value:this.machiningTimeTX, name:'加工',itemStyle:{color:"#00CC00"}},
{value:this.stopTimeTX, name:'停工',itemStyle:{color:"red"}},
{value:this.debugTimeTX, name:'调试',itemStyle:{color:"#FFA650"}}
],
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
],
color:[ //自定义的颜色
'rgb(0,0,0)',
'rgb(0,204,0)',
'rgb(254,0,0)',
'rgb(254,166,80)',
]
})
},
接口的调用:
// 占比图弹框
diagram(row){
this.closeTimeTX = row.closeTime
this.machiningTimeTX = row.machiningTime
this.stopTimeTX = row.stopTime
this.debugTimeTX = row.debugTime
this.dialoglookDiagram = true
this.$nextTick(() => {
this.initChart5()
})
}
实例图效果: