echarts.js 动态生成多个图表 使用vue封装组件
<div v-for="(item,index) in chartList" :key="index" style="width:33.15%;height:50%;color:white;border: 1px solid white;display:flex;">
<div :id="`chart${index}`" style="width:70%;height:100%;"></div>
</div>
paintGraphChange(){
this.chartList.forEach((val, index) => {
const myChart = echarts.init( document.getElementById(`chart${index}`),'dark')
this.chartList[index] = {
title: {top:"3%",position:'center',left:'60%',text: this.chartList[index].skillGroupName,textStyle:{fontSize:'20',textBorderType: [5, 10],textBorderDashOffset: 5,textBorderType: 'solid',color:'#5b9bd5'}},
xAxis: {type: 'category',data: ['语文', '数学','英语', '化学','物理','生物','政治'],nameLocation:'end',splitArea:{show:false},splitLine:{show: false}},
yAxis: {type: 'value',splitArea:{show:false},splitLine:{show: false}},
series: [{data:this.chartList[index].list,type: 'bar',barWidth: '20%',color:'#5b9bd5',label:{show:true,position:'top'},
itemStyle: {
normal:{
color: function (params){
var colorList = ['#5b9bd5','rgb(255,0,0)','rgb(146,208,80)','rgb(255,255,0)','rgb(0,176,240)','rgb(0,176,80)','rgb(112,48,160)'];
return colorList[params.dataIndex];
}
},}}],
grid:{left:"10%",right:"0%",top:"15%"}
}
myChart.setOption(this.chartList[index])
})
},