Google Chart API

234 views
Skip to first unread message

László Horváth

unread,
Jan 23, 2024, 9:37:35 AMJan 23
to Google Chart API
Dear Group!

I have a php code with a google chart. I've try everything but it doesn't work for me.
I have two variable:
Date: format like: '2024-01-23 14:36:43'
Value: format like: '234'.
This values come from mysql.

The error code is: Uncaught SyntaxError: missing ) after argument list (at index.php:17:33)

Thanks for your help and advice!

H.Laszlo

https://developers.google.com/chart/interactive/docs/datesandtimes

<?php
    $connection = mysqli_connect('localhost', 'xxxx', 'xxxx', 'database');
    $result = mysqli_query($connection, "SELECT id, date, value FROM table");

?>
<html>
  <head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript">

      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);

function drawChart() {

        var data = new google.visualization.DataTable();
        data.addColumn('date', 'Time of Day');
        data.addColumn('number', 'Rating');

    data.addRows([
        <?php
        if(mysqli_num_rows($result) > 0) {

            while($row = mysqli_fetch_array($result)) {

                $datum = $row['date'];
                $ertek = $row['value'];

                ?> [new Date( <?php echo $row['date']; ?> ), <?php echo $row['value']; ?> ], <?php
            }

        }
        ?>
    ]);
   
   
    var options = {
          title: 'Rate the Day on a Scale of 1 to 10',
          width: 900,
          height: 500,
          hAxis: {
            format: 'Y/m/d h:m:s',
            gridlines: {count: 15}
          },
          vAxis: {
            gridlines: {color: 'none'},
            minValue: 0
          }
        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));

        chart.draw(data, options);

        var button = document.getElementById('change');

        button.onclick = function () {

          // If the format option matches, change it to the new option,
          // if not, reset it to the original format.
          options.hAxis.format === 'M/d/yy' ?
          options.hAxis.format = 'MMM dd, yyyy' :
          options.hAxis.format = 'M/d/yy';

          chart.draw(data, options);
        };
}

    </script>
  </head>
  <body>
    <div id="chart_div"></div>
  </body>
</html>

László Horváth

unread,
Jan 23, 2024, 9:58:29 AMJan 23
to Google Chart API
I've made a little modification, so then now i see the chart but something wrong, all value in same column. Picture attached. Thank's the help.


chart.jpg


data.addRows([
        <?php
if(mysqli_num_rows($result) > 0) {

while($row = mysqli_fetch_array($result)) {

$datum = $row['datum'];
$datum_formated = date_format($datum, "Y, m, d");
$ertek = $row['ertek'];

?> [new Date(<?php echo $datum_formated; ?>), <?php echo $ertek; ?> ], <?php

}

}
?>
    ]);

calculator

unread,
Mar 28, 2024, 4:56:51 AMMar 28
to Google Chart API
yes thats true

23 Ocak 2024 Salı tarihinde saat 16:58:29 UTC+2 itibarıyla László Horváth şunları yazdı:
Reply all
Reply to author
Forward
0 new messages