Answer to Stack Overflow question: http://stackoverflow.com/questions/37825116/how-to-update-new-plotline-values-instead-of-removing-and-adding-new-ones-in-hig
author(s):
Mike Zavarello
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px"></div>
<button id="button" class="autocompare">Update first point</button>
JavaScript
$(function () {
$('#container').highcharts({
chart: {
type: 'line'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
// scatter plot line to serve as moveable plot line
type: 'scatter',
data: [[0,10],[11,10]],
lineWidth: 1,
marker: {
enabled: true // hide the markers (to show only the line)
},
showInLegend: true, // hide in legend
enableMouseTracking: false // prevent user from interacting with this line
}]
});
// button handler
var chart = $('#container').highcharts(),
y = 30;
$('#button').click(function () {
y += 10;
// update both ends of the scatter line
chart.series[1].data[0].update([0,y]);
chart.series[1].data[1].update([11,y]);
});
});