Here's my use of MySQL (in PHP) for a simple line graph:
<html>
<?php
// Start MySQL Connection
include('connect.php');
$SQL="SELECT DATE(recdate) AS 'RecordDate',FORMAT(AVG(Temperature),1) AS
'Temp',FORMAT(AVG(Humidity),1) AS 'Humidity' ,FORMAT(AVG(AmbientTemp),1) AS
'Ambient' FROM ResDataLog WHERE ABS(DATEDIFF(recdate,NOW())) < 375 GROUP BY
DATE(recdate) ORDER BY recdate"; //,FORMAT(AVG(Pressure),1) AS Pressure
$result=mysqli_query($dbh,$SQL);
$rowCount=mysqli_num_rows($result);
while ($row = mysqli_fetch_array($result)) {
$entry .=
"['".$row{'RecordDate'}."',".$row{'Temp'}.",".$row{'Humidity'}.",".$row{'Ambient'}."],";
};
//echo "Entry Array: </br>" . $entry . "</br>";
//close the connection
mysqli_close($dbh);
?>
<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 = google.visualization.arrayToDataTable([
['Date', 'Temp', 'Humidity', 'Ambient'],
<?php echo $entry ?>
]);
var options = {
title: 'Average Telemetry by Day',
curveType: 'function',
legend: { position: 'top' },
colors: ['black', 'blue', 'red']
};
var chart = new
google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 1200px; height: 600px"></div>
</body>
</html>
-------- Connect.php:
<?php
$MyUsername = ""; // enter your username for mysql
$MyPassword = ""; // enter your password for mysql
$MyHostname = ""; // this is usually "localhost" unless your database
resides on a different server
$MyDBName = "";
//mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$dbh = mysqli_connect($MyHostname , $MyUsername, $MyPassword, $MyDBName);
// Check connection
if (mysqli_connect_errno()) {
die('<br><p>{Connect.php} Failed to connect to MySQL:
'.mysqli_connect_error().'</p>');
}
// else {
// echo '<br><p>{Connect.php} Connection to MySQL server successfully
established.</p >';
// }
?>
On Fri, Oct 18, 2019 at 1:50 PM Shivakumar Chandrashekar <[email protected]>
wrote:
> Thanks Mike. Will wait :-)
>
> On Friday, October 18, 2019 at 5:47:42 AM UTC-7, Michael Brown wrote:
>>
>> I am trying to use MySQL as a data source for Gauge, but it's not working
>> yet.
>>
>> All of the examples I see have the Javascript in your Chart web page call
>> a PHP script on the database server. The PHP accesses the MySQL database
>> and formats the return data as JSON. The Javascript then feeds the JSON to
>> the Google chart API. It's too bad that Google didn't include direct SQL
>> handling in the Chart API.
>>
>> While the Google documentation shows the expected format of the JSON data
>> with row and col definitions, whatever I feed to the gauge causes it to not
>> display *anything*, the gauge just vanishes on the page. And there is no
>> error code or message being returned by the gauge, so I have no idea what
>> is wrong, short of trying dozens of slightly different formats.
>>
>> This is my general frustration with anything from Google, and I've done a
>> LOT of Android coding for my own needs. They provide a powerful and useful
>> system, but it's unnecessarily difficult to program to, and it's not
>> documented well enough to show examples for all use cases and error
>> handling is non-existent. And then they deprecate it a few years later and
>> you're screwed.
>>
>> When I get it working I'll come back and paste in the relevant code.
>>
>> --
>>
>> Mike Brown
>>
>> "Driving a gasoline sports car is going to feel like a steam engine with
>> a side of quiche." Elon Musk
>>
>>
>> On Thu, Oct 17, 2019 at 6:50 PM Shivakumar Chandrashekar <
>> [email protected]> wrote:
>>
>>> Friends, I am newbie for this. Just wanted to know if anyone used excel
>>> (preferably) or MySQL as data source and used this API. If yes, could you
>>> please share how to use ? any challenges faced ?
>>>
>>> --
>>> 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/b9cffd23-1f20-4dfe-b0b2-6c0f2988a44d%40googlegroups.com
>>> <https://groups.google.com/d/msgid/google-visualization-api/b9cffd23-1f20-4dfe-b0b2-6c0f2988a44d%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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/78de08b8-f76b-4995-9717-d3884170fb9f%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/78de08b8-f76b-4995-9717-d3884170fb9f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
Jim
--
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/CAEo%2BXt2aH_BKpbLe5dD1AOmgYkddssujjsqz6909%2B8W7wnC%2BEQ%40mail.gmail.com.