Graph and while

34 views
Skip to first unread message

Jean-Yves LEGRAS

unread,
Mar 17, 2021, 9:49:35 AM3/17/21
to Google Visualization API
Hey,

Do you know how to display some graph tanks to a while like that :

while ($i <= 3) {
    $i++;  
    /* La valeur affichée est $i avant l'incrémentation(post-incrémentation)  */
    echo $i;
    echo '<div id="curve_chart" style="width: auto; height: auto"></div>';
}

It doesn't work so I don't know how

Thanks for your answers

Ray Thomas

unread,
Mar 19, 2021, 9:20:09 PM3/19/21
to Google Visualization API
Hi Jean-Yves,

Problems with drawing multiple charts on a page comes up regularly, and it's usually because of the way scripts work. 

To show all the charts, you need to either wait until each chart fires its ready event - https://developers.google.com/chart/interactive/docs/events#the-ready-event or add a setTimeout function with the timer set to 0. As far as I know, the 0 time does not mean "do it now", it means "do it as soon as there's nothing else to be done"

I've tried to explain this in the section Multiple Data Tables, Multiple Charts at http://brisray.com/google-charts/multiple.htm

myString is an array of objects that contains everything needed to draw the charts.

var strLength = myString.length;
for (i=0; i < strLength; i++){
processChart(i);
}
    function processChart(i) { 
  setTimeout(function() { 
  function drawVisualization() {
var newString = myString[i]
  google.visualization.drawChart(newString);
  }
  google.charts.setOnLoadCallback(drawVisualization); 
  }, 0); 
}

Probably the only limit to how many charts you can have on a page is due to memory. https://indstate.edu/business/metrics has 24 charts on the page and uses a single event listener - pinched from https://www.kirupa.com/html5/handling_events_for_many_elements.htm

Reply all
Reply to author
Forward
0 new messages