Google bar chart

40 views
Skip to first unread message

Chris Rasmussen

unread,
Sep 21, 2017, 5:45:13 AM9/21/17
to Google Visualization API
Hi there, 

Not really a Script shark yet. PHP is more my game.. 

I want to show a google bar chart from a mysqli database. 

Here is my code..:

<?PHP


include "config.php";
for($i=0; $i<=6; $i++){

$dato=date('Y-m-d',strtotime("-".$i." days"));
$hent=mysqli_query($con,"SELECT * FROM WithdrawalLog WHERE tid LIKE '%".$dato."%' AND Location='Location1' ORDER BY id DESC LIMIT 0, 1000");
while($row=mysqli_fetch_array($hent)){
$amount=abs($row["antalLiter"]);
$loction1=$location1+$amount;
}


$hent=mysqli_query($con,"SELECT * FROM WithdrawalLog WHERE tid LIKE '%".$dato."%' AND Location='Location2' ORDER BY id DESC LIMIT 0, 1000");
while($row=mysqli_fetch_array($hent)){
$amount=abs($row["antalLiter"]);

$location1=$location1+$amount;

}
$resultat .= "['".$dato."', '".$location1."','".$location2."'],";
$location1=0;
$location2=0;
}
?>
<html>
<head>

    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Dato', 'Location1', 'Location2'],

<?PHP
echo $resultat;
?>
  
      ]);

        var options = {
          chart: {
            title: 'Last  7 days',
            subtitle: 'Date and location',
          }

        };

        var chart = new google.charts.Bar(document.getElementById('columnchart_material'));

        chart.draw(data, google.charts.Bar.convertOptions(options));
      }
    </script>



<meta http-equiv="refresh" content="60" > 
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<div id="columnchart_material" style="width: 90%; margin:auto; height: 500px;"></div>

</body>
</html>




Here is how the chart is processed..



My problem is that the chart seems to show the first 2  entrys as negative numbers although they are positive. (when i mouseover the column it even shows a positive number). 

How can i alter this in the code to get a correct vertical left side scale ?


Chris Rasmussen

unread,
Sep 21, 2017, 7:56:25 AM9/21/17
to Google Visualization API
Never mind, found out my self that i have put quotationmarks on actual numbers, that is obviously a no-go :)
Reply all
Reply to author
Forward
0 new messages