1.legend计算占比
total:0,
znum:0
this.data.forEach(val => this.total += parseInt(val.value));
for (let i = 0; i < nv.length; i++) {
if (i != nv.length - 1) {
this.znum = this.znum + Number(parseFloat((nv[i].value / this.total) * 100).toFixed(2));
}
}
formatter: function (name) {
if (show == false) {
return name + ' ' + '****';
} else {
for (let i = 0; i < that.data.length; i++) {
if (that.data[i].name == name) {
if (that.data[i].value != 0) {
if (i == that.data.length - 1) {
return name + ' ' + parseFloat(100 - that.znum).toFixed(2) + '%';
} else {
return (
name +
' ' +
parseFloat((that.data[i].value / that.total) * 100).toFixed(2) +
'%'
);
}
} else {
return name + ' ' + '0%';
}
}
}
}
}
2.设置圆环中间文字的位置
title: {
show: true,
text: '第一行文字',
left: '23.5%',
top: '38%',
subtext:'第二行文字',
textAlign:'center',
textStyle: {
color: '#fff',
fontSize: 16,
align: 'center'
},
subtextStyle: {
fontSize: 12,
fontWeight:'bold',
align: 'center',
color: '#fff',
align: 'center'
}
},
3.饼图设置动态切换
selectValue:"",
selectTitle:""
this.echarts.dispatchAction({
type: "highlight",
seriesIndex: [0,1,2],
dataIndex: i
})
this.echarts.dispatchAction({
type: "downplay",
seriesIndex: [0,1,2],
dataIndex: i-2
})
this.$nextTick(() => {
this.echarts = this.$echarts.init(this.$refs.echarts);
this.setOption(this.show);
let i=0;let j=0;
this.timer=setInterval(()=>{
if(i<this.pieData.length){
this.echarts.dispatchAction({
type: "highlight",
seriesIndex: [0,1,2],
dataIndex: i
})
i+=2;
}else{
i=0;
this.echarts.dispatchAction({
type: "highlight",
seriesIndex: [0,1,2],
dataIndex: i
})
i+=2;
}
if (j == this.data.length - 1) {
this.selectValue=parseFloat(100 - this.znum).toFixed(2) + '%';
this.selectTitle=this.data[j].typeName;
j=-1;
} else {
this.selectValue=parseFloat((this.data[j].average / this.total) * 100).toFixed(2) +'%'
this.selectTitle=this.data[j].typeName;
}
this.setOption(this.show);
j+=1;
setTimeout(()=>{
this.echarts.dispatchAction({
type: "downplay",
seriesIndex: [0,1,2],
dataIndex: i-2
})
},1200)
},3000)
});
4.设置数据修改后触发重新渲染动画
this.echarts.dispose();
this.echarts = this.$echarts.init(this.$refs.echarts);
5.设置颜色渐变
color:new _this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 1,
color: _this.bgColor.color1
},
{
offset: 0,
color: _this.bgColor.color2
}
])
6.设置坐标轴的样式
tooltip: {
backgroundColor: 'rgba(30, 30, 30, 0.55)',
borderColor: 'rgba(30, 30, 30, 0.55)',
textStyle: {
color: '#fff'
}
},
xAxis: {
axisLabel: {
color: '#1492C9',
rotate: 0,
margin: 5,
fontSize: 15,
interval: 0
},
axisTick: {
show: false
},
splitLine: {
show: false
},
axisLine: {
show: true,
lineStyle: {
color: '#384267'
}
},
data: this.xAxis
},
yAxis: {
nameTextStyle: {
color: '#1492C9',
padding: [0, 0, 10, 0],
fontSize: 14
},
axisLabel: {
color: '#1492C9',
fontSize: 15
},
axisTick: {
show: false,
lineStyle: {
color: '#384267'
}
},
splitLine: {
show: true,
lineStyle: {
color: 'rgba(56,66,103,0.5)'
}
},
axisLine: {
}
},
series: {
large: true,
type: 'line',
smooth: false,
itemStyle: option.seriesLineStyle || {
width: 2.5,
color: '#F2597F',
shadowColor: '#fff',
shadowBlur: 15
},
showSymbol: true,
symbolSize: 6,
areaStyle: option.areaStyle && {
opacity: 0.58,
color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 0.6, [
{
offset: 0,
color: option.areaStyle.color1
},
{
offset: 1,
color: option.areaStyle.color2
}
])
},
emphasis: {
focus: 'series'
},
data: option.series || []
}