1.echarts monitors legend, and dynamically setting the legend attribute is invalid.
Dynamically changing the icon in the legend, myChart.setOption(option) will not work, but the local setting will take effect.
myChart.on('legendselectchanged', function (params) {
if (params.selected[params.name]) {
data1[data.indexOf(params.name)].icon = 'circle'
myChart.setOption({
legend: {
data: data1
}
})
} else {
data1[data.indexOf(params.name)].icon = 'none'
myChart.setOption({
legend: {
data: data1
}
})
}
})
2.The color of the legend icon is inconsistent with the color of the line chart
Main settingsitemStyle
let colors = ['red','green', 'white','yellow', 'pink','blue','orange','gray', 'purple']
legend:{
data:[
name: data[i],
icon: 'none',
textStyle: {
width: 4,
type: 'solid',
color: colors[i],
fontSize: 32,
padding: [0, 0, 0, 12],
},
itemStyle: {
color: colors[i],
},
]
}
3.Tooltip’s formatter data read is undefined
Inside is an object and an array. You need to filter out the array.
tooltip: {
trigger: 'axis',
formatter: function (params) {
let result = params[0].name + '<br />'
params.forEach(function (item) {
//要判断是不是数组
if (res[item.seriesIndex] instanceof Array) {
}
}
}
4. Move the mouse into the line chart to enlarge it
Add the zoom configuration item to the series configuration item
series:[
symbolSize: 11,
emphasis: {
scale:2,
},
]