With this solution I get the following Jason form the PHP:
{"cols":[{"label":"DatumZeit","type":"string"},{"label":"Origin AZ
[ms]","type":"number"},{"label":"API AZ
[ms]","type":"number"}],"rows":[{"c":[{"v":""},{"v":0},{"v":58}]},{"c":[{"v":""},{"v":0},{"v":72}]},{"c":[{"v":""},{"v":0},{"v":72}]},{"c":[{"v":""},{"v":0},{"v":67}]},{"c":[{"v":""},{"v":0},{"v":69}]},{"c":[{"v":""},{"v":0},{"v":88}]},{"c":[{"v":""},{"v":0},{"v":70}]},{"c":[{"v":""},{"v":0},{"v":68}]},{"c":[{"v":""},{"v":0},{"v":271}]},{"c":[{"v":""},{"v":0},{"v":70}]}]}
But I do not know, why the first v:-values are empty and the second
v-values are all 0?
In fact with one line in the graph these values are not missing. (And they
are present in the DB).
<?php
//$_ra = $_GET["ra"];
mysql_connect("XXXXXX:YYY","USer","PW");
mysql_select_db("test");
$result = mysql_query("SELECT (DATE_FORMAT(t, '%T')), rt FROM
zdf_rt_testzdf Order by t DESC LIMIT 10");
$result_API = mysql_query("SELECT (DATE_FORMAT(t, '%T')), rt FROM
zdf_rt_testzdf_API Order by t DESC LIMIT 10");
$table = array();
$table['cols'] = array(
// Labels for your chart, these represent the column titles
// Note that one column is in "string" format and another one is in
"number" format as pie chart only required "numbers" for calculating
percentage and string will be used for column title
array('label' => 'DatumZeit', 'type' => 'string'),
array('label' => 'Origin AZ [ms]', 'type' => 'number'),
array('label' => 'API AZ [ms]', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($result) && $r_API =
mysql_fetch_assoc($result_API)) {
$temp = array();
// the following line will be used to slice the Pie chart
$temp[] = array('v' => (string) $r["(DATE_FORMAT(t, '%T'))"]);
// Values of each slice
$temp[] = array('v' => (int) $r['rt']);
$temp[] = array('v' => (int) $r_API['rt']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
//$json_data = json_encode($data);
//print $json_data;
//file_put_contents('your_json_file.json', $json_data);
mysql_close();
?>
RBTCGP schrieb am Samstag, 19. September 2020 um 21:36:26 UTC+2:
> I have a line chart, that gets data from a DB by the use of a PHP-Script.
>
> Now I would like to display a second line in the same chart getting data
> from the same DB but from another table.
>
> Do I have to add code in the google graph HTML-page or just in the
> PHP-Script?
>
> <?php
> //$_ra = $_GET["ra"];
> mysql_connect("<IP>:<PORT>","<USER>","<PW>");
> mysql_select_db("test");
>
> $result = mysql_query("SELECT (DATE_FORMAT(t, '%T')), rt FROM <Table>
> Order by t DESC LIMIT 10");
>
> $table = array();
> $table['cols'] = array(
>
> // Labels for your chart, these represent the column titles
> // Note that one column is in "string" format and another one is in
> "number" format as pie chart only required "numbers" for calculating
> percentage and string will be used for column title
> 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, '%T'))"]);
>
> // Values of each slice
> $temp[] = array('v' => (int) $r['rt']);
> $rows[] = array('c' => $temp);
> }
>
> $table['rows'] = $rows;
> $jsonTable = json_encode($table);
> echo $jsonTable;
>
> mysql_close();
> ?>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-visualization-api/702f7d5b-a40a-4c22-a38e-674da29c8879n%40googlegroups.com.