0

I am working on a project where I am making use of the Google Charting API and I want to populate the chart using json with php mysql.

<?php 

$sql = $db->query("SELECT  COUNT(depots_id) AS count FROM inputs WHERE etat_input ='Valider'");


$results = array();
while ($var = $sql->fetch(PDO::FETCH_ASSOC)) {
        $results[] = $var;

}                   

$pie_chart_data = array();
foreach ($results as $result) {
    $pie_chart_data[] = array((int)$result['count']);
}
$pie_chart_data = json_encode($pie_chart_data);
?>

And the code javascript to building the chart :

<script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {

        var data = google.visualization.DataTable();
        data.addColumn('number','depots_id');
        data.addRows({$pie_chart_data});

        var options = {
          title: 'My Daily Activities'
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
      }
    </script>




 <div class="col-md-6 col-sm-6 col-xs-12">
              <div id="piechart" style="width: 900px; height: 500px;"></div>


            </div>

but it shows me no results.

1 Answer 1

0

A similar question was asked here, and may help you identify the issue.

If this still doesn't help, could you confirm that your PHP correctly outputs the JSON as expected (and even post an example of the output)?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.