Add plot when single series
Add plot when single series
by Sanjay
HTML
<script src="http://highcharts.com/js/testing.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="height: 400px"></div>
JavaScript
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
plotOptions: {
series: {
events: {
hide: function(e) {
var seriesIndex = this.index;
var series = this.chart.series;
var visibleSeries = series.filter(
s => s.visible
);
if (visibleSeries.length === 1) {
this.yAxis.addPlotLine({
color: '#FF0000',
width: 2,
value: visibleSeries[0].userOptions.max,
id: 'p-1'
})
this.yAxis.addPlotLine({
color: '#0000FF',
width: 2,
value: visibleSeries[0].userOptions.min,
id: 'p-2'
});
} else {
this.chart.series.map(s=>{s.yAxis.removePlotLine('p-1');s.yAxis.removePlotLine('p-2');})
}
},
show: function(e) {
var seriesIndex = this.index;
var series = this.chart.series;
var visibleSeries = series.filter(
s => s.visible
);
if (visibleSeries.length === 1) {
this.yAxis.addPlotLine({
color: '#FF0000',
width: 2,
value: visibleSeries[0].userOptions.max,
id: 'p-1'
})
this.yAxis.addPlotLine({
color: '#0000FF',
width: 2,
value: visibleSeries[0].userOptions.min,
id:...