scrollable time line

16 views
Skip to first unread message

beginnerGG

unread,
Oct 4, 2016, 11:45:20 AM10/4/16
to Google Visualization API
the option explorer:{} does only work with continuous data types, like number or date. My chart.draw gets its data in JSON format. Now how can I put data type values for the x-axis into the JSON-array in my .PHP-script, that reads that data with an sql-query from a data base. PHP does use the string format and does not know any data format.

Here comes the HTML:
function drawChart() {
      var jsonData = $.ajax({
          url: "Antwortzeiten.php?seite=Start",
          dataType:"json",
          async: false
          }).responseText;
      
      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(jsonData);

      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.LineChart(document.getElementById('chart_start_div'));
      chart.draw(data, {explorer: {axis: 'horizontal'}, width: 800, height: 240});
    }

Here comes the PHP:

<?php
$_seite = $_GET["seite"];
mysql_connect("localhost:XXXX","YYYY","PW");
mysql_select_db("test");

$result = mysql_query("SELECT (DATE_FORMAT(t, '%d.%m.%y')), rt FROM zdf_zykl Where s='$_seite' Order by t DESC LIMIT 10");

$table = array();
$table['cols'] = array(

    array('label' => 'DatumZeit', 'type' => 'string'),
    array('label' => 'AZ [ms]', 'type' => 'number')

);

$rows = array();
while($r = mysql_fetch_assoc($result)) {
    $temp = array();
    // the following line will be used to slice the Pie chart
    $temp[] = array('v' => (string) $r["(DATE_FORMAT(t, '%d.%m.%y'))"]);

    // Values of each slice
    $temp[] = array('v' => (float) $r['rt']);
    $rows[] = array('c' => $temp);
}

$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;

mysql_close();
?>
Reply all
Reply to author
Forward
0 new messages