nhicap19,
I asked you only to remove redundant code. The less code = the easier and faster for me to understand and find a solution
But it's ok, I managed to simplify your demo on my own.
It wasn't difficult to implement my solution to your code - the only thing I had to do is to change plotBand index from 0 to 1 (because the first is your plotLine, not plotBand).
The only thing you have to change in your code is:
Code: Select all
function(chartObj) {
chartObj.plotBandsVisible = true;
$('#btn').click(function() {
console.log(chartObj)
var plotBand = chartObj.xAxis[0].plotLinesAndBands[1];
if (chartObj.plotBandsVisible) {
chartObj.plotBandsVisible = false;
plotBand.svgElem.hide();
} else {
chartObj.plotBandsVisible = true;
plotBand.svgElem.show();
}
});
});
And add the afterSetExtremes() function:
Code: Select all
afterSetExtremes() {
let chart = this.chart;
if (!chart.plotBandsVisible) {
chart.xAxis[0].plotLinesAndBands[1].svgElem.hide();
chart.plotBandsVisible = false;
}
}
jsFiddle:
http://jsfiddle.net/BlackLabel/scfjn9gz/
Best regards!