Here is my java script code:
<script type="text/javascript" src="
http://www.google.com/jsapi"></
script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
function drawVisualization() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'x');
data.addColumn('number', 'WTG 01');
data.addColumn('number', 'WTG 02');
data.addColumn('number', 'WTG 03');
data.addColumn('number', 'WTG 04');
data.addColumn('number', 'WTG 05');
data.addColumn('number', 'WTG 06');
data.addColumn('number', 'WTG 07');
<?php
while($row = mysql_fetch_array($result))
{
$ts = $row["timestamp_real"];
$power = $row["power_avg"];
$old = array("-"," ",":");
$new = array(";",";",";");
$newts = str_replace($old, $new, $ts);
$seppts = explode(";",$newts);
$timestamp = "$seppts[3]:$seppts[4] $seppts[2]-$seppts[1]-
$seppts[0]";
$rowb2w2 = mysql_fetch_array($rb2w2); $pb2w2 =
$rowb2w2["power_avg"];
$rowb2w3 = mysql_fetch_array($rb2w3); $pb2w3 =
$rowb2w3["power_avg"];
$rowb2w4 = mysql_fetch_array($rb2w4); $pb2w4 =
$rowb2w4["power_avg"];
$rowb1w3 = mysql_fetch_array($rb1w3); $pb1w3 =
$rowb1w3["power_avg"];
$rowb1w1 = mysql_fetch_array($rb1w1); $pb1w1 =
$rowb1w1["power_avg"];
$rowb1w2 = mysql_fetch_array($rb1w2); $pb1w2 =
$rowb1w2["power_avg"];
echo 'data.addRow(["'.$timestamp.'", '.$power.', '.$pb2w2.', '.
$pb2w3.', '.$pb2w4.', '.$pb1w3.', '.$pb1w1.', '.$pb1w2.']);';
}
mysql_close();
?>
new
google.visualization.LineChart(document.getElementById('visualization')).
draw(data, {curveType: "function",
title: 'Last 12 hours production [kWh]!',
width: 800, height: 240,
vAxis: {maxValue: 100}}
);
}
google.setOnLoadCallback(drawVisualization);
</script>
Unfortunately I can not grant access to the site, the data are quite
confidential. I know for now that the php script is not quite
optimized, and that could be the issue for the delay in generating the
script.
I`v got 7 tables in my SQL that need to be queried, and witch retrieve
the last 72 rows (data are 10-min interval and I need the last 12
hours) so i request the last 72 values from each table and pass them
to javascript, the actual php is messy for now.
Here is the PHP code, take in mind that the tables rows are not the
same, some have more values than others.
$connect = mysql_connect($db_host,$db_user,$db_pass) or die ("Could
not connect!");
mysql_select_db($db_name) or die ("Could not find data base!");
$prep_count = mysql_query("SELECT * FROM `$db_baia2_wtg01`");
$allrows = mysql_num_rows($prep_count);
$from = $allrows-72;
$to = $allrows;
$prep_count2 = mysql_query("SELECT * FROM `$db_baia1_wtg03`");
$allrows2 = mysql_num_rows($prep_count2);
$from2 = $allrows2-72;
$to2 = $allrows2;
$prep_count3 = mysql_query("SELECT * FROM `$db_baia1_wtg01`");
$allrows3 = mysql_num_rows($prep_count3);
$from3 = $allrows3-72;
$to3 = $allrows3;
$prep_count4 = mysql_query("SELECT * FROM `$db_baia1_wtg02`");
$allrows4 = mysql_num_rows($prep_count4);
$from4 = $allrows4-72;
$to4 = $allrows4;
$query = "SELECT * FROM `$db_baia2_wtg01` LIMIT $from,$to";
$result = mysql_query($query);
$qb2w2 = "SELECT * FROM `$db_baia2_wtg02` LIMIT $from,$to"; $rb2w2 =
mysql_query($qb2w2);
$qb2w3 = "SELECT * FROM `$db_baia2_wtg03` LIMIT $from,$to"; $rb2w3 =
mysql_query($qb2w3);
$qb2w4 = "SELECT * FROM `$db_baia2_wtg04` LIMIT $from,$to"; $rb2w4 =
mysql_query($qb2w4);
$qb1w3 = "SELECT * FROM `$db_baia1_wtg03` LIMIT $from2,$to2"; $rb1w3
= mysql_query($qb1w3);
$qb1w1 = "SELECT * FROM `$db_baia1_wtg01` LIMIT $from3,$to3"; $rb1w1
= mysql_query($qb1w1);
$qb1w2 = "SELECT * FROM `$db_baia1_wtg02` LIMIT $from4,$to4"; $rb1w2
= mysql_query($qb1w2);
I am considering also to pass the php query to a JSON type of data
manipulation as in the documentation, it would be better ?
As I seen from the docs, I think the manipulation using JSON style is
more easy to customize the chart.
Am I doing something wrong here ? or do I see things wrong ?
Thnx !