Jugal | Persist crosshair/cursor as plot lines on click | Highchart & Highstock
http://stackoverflow.com/questions/12061230/highcharts-keep-vertical-line-on-click-event
Jugal Thakkar
http://jugal.me/
by Jugal Thakkar
HTML
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js" ></script>
<script type="text/javascript" src="http://code.jugal.me/js/jugalsLib.js" ></script>
<script type="text/javascript" src="http://code.highcharts.com/stock/highstock.src.js" ></script>
<script type="text/javascript" src="http://code.highcharts.com/stock/modules/exporting.src.js" ></script>
<div id="container"></div>
CSS
#container{ min-width:500px;
}
JavaScript
var myPlotLineId = "myPlotLine";
var chartingOptions = {
chart: {
renderTo: 'container',
events: {
click: function(evt) {
var chart = this;
index = chart.inverted ? chart.plotHeight + chart.plotTop - evt.chartY : evt.chartX - chart.plotLeft;
var xValue = chart.series[0].tooltipPoints[index].x;
var xAxis = evt.xAxis[0].axis;
$.each(xAxis.plotLinesAndBands, function() {
if (this.id === myPlotLineId) {
this.destroy();
}
});
xAxis.addPlotLine({
value: xValue,
width: 1,
color: 'red',
//dashStyle: 'dash',
id: myPlotLineId
});
}
}
}
};
chartingOptions = $.extend({}, jugalsLib.getBasicChartOptions(), chartingOptions);
var chart = new Highcharts.StockChart(chartingOptions);