Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Highcharts Dynamic Chart

Highcharts Dynamic Chart

In this chapter we will introduce Highcharts dynamic charts.

We learned the Highcharts configuration syntax in the previous chapters. Now let's look at other Highcharts configurations.


Update the Spline Chart Every Second

chart.events

Add the load method (chart load event) to the chart.event property. Generate random data points every 1000 milliseconds and create the chart.



chart: {

   events: {

      load: function () {

         // Chart updates once per second

         var series = this.series[0];

         setInterval(function () {

            var x = (new Date()).getTime(), // 当期时间

            y = Math.random();

            series.addPoint([x, y], true, true);

         }, 1000);

      }

   }

}

Example

Filename: highcharts_dynamic_spline.htm









Highcharts 教程 | Runoob Tutorial(runoob.com)







The output of the above example is:

Highcharts Pie ChartHighcharts Pie Chart


Add Data by Clicking

chart.events

Add the click method (the click event that occurs on the chart's plotting area) to the chart.event property. This method adds a new data point when a click occurs on the chart's plotting area.



chart: {

   events: {

      click: function (e) {

         // Get click coordinates and data item

         var x = e.xAxis[0].value,

         y = e.yAxis[0].value,

         series = this.series[0];

         // Add clicked coordinates

         series.addPoint([x, y]);

      }

   }

}

Example

Filename: highcharts_dynamic_click.htm







Highcharts 教程 | Runoob Tutorial(runoob.com)

   

   





The output of the above example is: