Display a Bar Chart using Google Chart API in php mysql Display a Bar Chart using Google Chart API in php mysql php php

Display a Bar Chart using Google Chart API in php mysql


I know that your post was an "answer" but I figured I would chime in. If you are looking to dynamically enter data into a Google chart you can simply echo out into the javascript using PHP . The php can be used to get information from your server or mysql table.

Here is an example:

    <?php   $i = 0; $grab = mysql_query("SELECT * FROM `productList` WHERE 1");    $pricelist = mysql_fetch_array($grab);    $numberofproducts = mysql_num_rows($grab);                              ?>           <script type="text/javascript" src="https://www.google.com/jsapi"></script>    <script type="text/javascript">    google.load("visualization", "1", {packages:["corechart"]});    google.setOnLoadCallback(drawChart);    function drawChart() {    var data = google.visualization.arrayToDataTable([      ['parts', 'Prices'],      ['Number of Products',  <?php echo $numberofproducts;?>],    ]);    var options = {      title: 'Number of Products',      hAxis: {title: '', titleTextStyle: {color: 'red'}},                width: 980,                height: 200    };    var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));    chart.draw(data, options);  }