Search code examples
highchartshighcharts-ng

Highstock charts | How do I store a series start and end value in variables?


I am developing a chart tat has two series and shows the aggregated(so the number is added to the point before it, so it is always rising) number of enrolled students vs the aggregated number of certified students with each points plotted when then student enrols or is certified.

What I am wanting to do is display in another part of the page is the rate of change between the start and end points displayed at the time and is updated every time the date range changes.

So how do I store the start and end point of each series into a variable for me to use and is automatically updated every time the date range is changed.


Solution

  • Like I said in the comment, you should be able to use chart.series.array for getting all of the values in your chart.

    $(function() {
      $('#container').highcharts({
        series: [{
          data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
        }]
      }, function(chart) {
        $('.btn').click(function() {
          var series = chart.series;
          alert('start: ' + series[0].data[0].y + '\nend: ' + series[0].data[series[0].data.length - 1].y)
        });
      });
    });
    

    Here you can see simple example how it can work: http://jsfiddle.net/Luf9bfy0/