Google Chart API Data

后端 未结 1 1448
执念已碎
执念已碎 2021-01-27 06:39

How do I populate the Google Chart API with my own Server side data i.e. in PHPMySQL.

Currently I have the following data:

function drawChart()
{
 // Cre         


        
相关标签:
1条回答
  • 2021-01-27 07:34

    Before the JavaScript-Code of the Charts API you have to get your data out of your database:

    //Your database query goes here
    $list = mysql_query("SELECT city,crimes FROM TABLE");
    while($row = mysql_fetch_assoc($list)){
      $data[] = "['".$row['city']."', ".$row['crimes']."]";
    }
    $data_for_chart = implode(",\n"$data);
    

    Now replace in your JS-code:

    data.addRows([
             ['Cardiff', 300],
             ['London', 900],
             ['Manchester', 500],
             ['Dublin', 400],
             ['Liverpool', 600]
             ]);
    

    With:

    data.addRows([
             <?php echo $data_for_chart; ?>
             ]);
    
    0 讨论(0)
提交回复
热议问题