我找到了答案,但并不像我希望的那样容易:
图表传奇更新和图例。带外部变量的labelFormatter
var legendsStatus = {};
使用labelFormatter的自定义图例:
legend :{
useHTML: true,
symbolWidth: 0,
labelFormatter: function () {
return '<div>' +
'<div style="border-radius: 50%; width: 10px; height: 10px; background-color: ' + this.color +'; display: inline-block; margin-right:5px"> </div>' +
"<span style='color:" + this.color + "; font-family:proximaNovaBold'> " + this.name + " </span>" +
'</div>'
}
},
使用图表的事件侦听器。传奇更新:
plotOptions: {
series: {
marker: {
enabled: false
},
events : {
legendItemClick : function(){
legendsStatus[this.name] = this.visible;
this.chart.legend.update( {
useHTML: true,
symbolWidth: 0,
labelFormatter: function () {
// legend status = visible
if (!legendsStatus[this.name])
return '<div>' +
'<div style="border-radius: 50%; width: 10px; height: 10px; background-color: ' + this.color +'; display: inline-block; margin-right:5px"> </div>' +
"<span style='color:" + this.color + "; font-family:proximaNovaBold'> " + this.name + " </span>" +
'</div>'
// legend status = invisible
return '<div>' +
'<div style="border-radius: 50%; width: 10px; height: 10px; background-color: #cccccc; display: inline-block; margin-right:5px"> </div>' +
"<span style='color: #cccccc; font-family:proximaNovaBold'> " + this.name + " </span>" +
'</div>'
}
});
}
}
}
},