Hi Guys:
The screen shot above shows the weather data being displayed and updating every 5 minutes. So now the next thing I want to do is to add a basic line graph (using google charts) that connects to my database and then displays that information at the bottom. For starters, lets say I just want to graph the temperature (y-axis) vs. the time (x-axis). This data is already stored and available in my database table (see below).
So, if you look at my table columns, you can see I have the temperature readings (column = temperature) and then the date/time (column = stamp). So the goal is to take my current code in my index file (file used on web-server) and the code to create this simple graph.
Lastly, I've included a copy of my current PHP code that displays the data. I'm very illiterate on this interface I'm trying to build but any help is greatly appreciated.
Thanks,
Andrew
<?php$hostname = "localhost";$username = "xxxxxx";$password = "xxxxxx";$database = "ecb";$tabel = "eurorates";// Create connection$conn = mysqli_connect($hostname, $username, $password, $database);// Check connectionif (!$conn) {die("Connection failed: " . mysqli_connect_error());}//set array variable$results = array();//talk to the db$sql="SELECT * FROM eurorates WHERE currency = 'GBP' ORDER BY date DESC limit 100";$result = mysqli_query($conn, $sql);//count the rows and fields$totalRows = mysqli_num_rows($result);$totalFields = mysqli_num_fields($result);//start the loopfor ( $i = 0; $i < $totalRows; ++$i ) {//make it 2 dim in case you change your order$results[$i] = mysqli_fetch_array($result);}?><html><head><script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load( 'visualization', '1', { 'packages': [ 'corechart' ] } );google.setOnLoadCallback( drawChart );function drawChart() {var data = new google.visualization.DataTable();data.addColumn( 'string', 'Datum' );data.addColumn( 'number', 'Rate' );data.addRows(100);<?php$i = 0;$numofloops = 100;while($i < $numofloops){echo "data.setValue($i, 0, '" . $results[$i]["date"] . "');";echo "data.setValue($i, 1, " . $results[$i]["rate"] . ");";$i++;}?>var options = {title: 'Echangerate EUR - GBP',vAxis: {title: "Rate"},hAxis: {title: "Date"},colors: ['red','#004411']};var chart = new google.visualization.LineChart(document.getElementById('chart_div'));chart.draw( data, options);}</script></head><body><div id="chart_div" style="width: 1500px; height: 800px;"></div></body></html>
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/af0126ef-d873-4380-b4d9-487ab6fd72a5%40googlegroups.com.--
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 google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To post to this group, send email to google-visua...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/af0126ef-d873-4380-b4d9-487ab6fd72a5%40googlegroups.com.