You can create an empty series that mimics the characteristics of the plot line (color, dash style ...). Then, if necessary, you can use the event legendItemClickto βlink itβ to the plot line.
, ID :
plotLineId = 'myPlotLine'; // To identify for removal
// Plot line options for adding
plotLineOptions = {
color: '#FF0000',
id: plotLineId,
width: 2,
value: 5.5,
dashStyle: 'shortdash'
};
:
xAxis: {
plotLines: [ plotLineOptions ]
}
:
series: [
{
color: '#FF0000',
name: 'My plotline',
dashStyle: 'shortdash',
marker: {
enabled: false
},
events: {
legendItemClick: function(e) {
if(this.visible) {
this.chart.xAxis[0].removePlotLine(plotLineId);
}
else {
this.chart.xAxis[0].addPlotLine(plotLineOptions);
}
}
}
}
]
JSFiddle , ( , ).