User avatar
Eugene_
Posts: 5
Joined: Mon Jun 25, 2018 4:40 am
Location: Europe

Is there a way to synchronize auto-update (multiple charts)?

There are several charts on my page. There are several series on each chart.

Each chart contains the code below.
(GRAPH1, GRAPH2...etc - just copy of this code for each chart.)

Part of the code

Code: Select all

chart: 
{zoomType: 'x',
events:
{
load: function () {
//not optimal, need a loop?
var GRAPH1series_0 = this.series[0];
var GRAPH1series_1 = this.series[1];
var GRAPH1series_2 = this.series[2];
var GRAPH1series_3 = this.series[3];
var GRAPH1series_4 = this.series[4];
var GRAPH1series_5 = this.series[5];


setInterval(function ()
{

$.each(GRAPH1names, function (i, name) {
current_time=(new Date()).getTime()+17400000; // current time

$.getJSON('actions.php?get_live_data&cryptocurrency_id_name='+name, function(GRAPH1live_data) {

if (i==0) GRAPH1series_0.addPoint([current_time, GRAPH1live_data], true, true);
if (i==1) GRAPH1series_1.addPoint([current_time, GRAPH1live_data], true, true);
if (i==2) GRAPH1series_2.addPoint([current_time, GRAPH1live_data], true, true);
if (i==3) GRAPH1series_3.addPoint([current_time, GRAPH1live_data], true, true);
if (i==4) GRAPH1series_4.addPoint([current_time, GRAPH1live_data], true, true);
if (i==5) GRAPH1series_5.addPoint([current_time, GRAPH1live_data], true, true);


});
});
}, 10000); //timer (update interval)
}
}


When several charts are placed on a page they are not updated synchronously. And this is understandable - the timer starts only when the script is inserted. This is a fraction of a second. But the longer the auto-update of several charts, the more the difference is visible.
Perhaps I need a single timer for all graphs. Or an appropriate event (like load_all: function?) for all charts. Not for everyone as it is now.
Is there such an event, option or example?
Is there a way to synchronize auto-update (multiple charts)?
rafalS
Posts: 2665
Joined: Thu Jun 14, 2018 11:40 am

Re: Is there a way to synchronize auto-update (multiple char

Hi, Eugene_!

There is not any event/option for every chart, but you can just put all your charts to the global variable and use one setInterval function for all your charts (with all series). You can look at this example: https://jsfiddle.net/gh/get/library/pur ... uge-solid/

Let me know if it still is not clear to you and you need any additional help/info. I will take a closer look at your charts and we will try to face all problems.

Best regards!
Rafał
Rafal Sebestjanski,
Highcharts Team Lead

Return to “Highcharts Stock”