arduino graph with PHPgraphlib

Hello , i' trying to make a graph using the temperature data read by my arduino , These data are loaded in a database thanks to a php script, I'm trying to use this library http://www.ebrueggeman.com/ but i can't create my graph. Anyone could help me? The code i've written is this.

<?php

include("phpgraphlib.php"); 

$graph=new PHPGraphLib(500,400);

$hostname="******";
$username="*****";
$password="******";
$conn=mysql_connect($hostname,$username,$password);
if(!conn){
die("Error.");
exit();
}
echo("OK.");
mysql_select_db("domotica");
$data = array();
$sql="SELECT temp,COUNT(*) as 'count' FROM temp";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
if ($result) {
  while ($row = mysql_fetch_assoc($result)) {
  $temp = $row["temp"];
  $count=$row["count"];
  $data[$temp] = $count;    
  }
}
$graph->addData($data);
$graph->setTitle("Temperatura");
$graph->setBars(false);
$graph->setLine(true);
$graph->setDataPoints(true);
$graph->setDataPointColor("yellow");
$graph->setDataValues(true);
$graph->setDataValueColor("blue");
$graph->createGraph();

?>

The table is like this:

+-------+---------+------+-----+---------+----------------+
| Field | Type    | Null | Key | Default | Extra          |
+-------+---------+------+-----+---------+----------------+
| ID    | int(11) | NO   | PRI | NULL    | auto_increment |
| temp  | int(11) | NO   |     | NULL    |                |
+-------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

Or if you use an other way to create graph for arduino i would be happy if you explain it to me. Thanks :smiley:

luigialab:
Or if you use an other way to create graph for arduino i would be happy if you explain it to me.

The simplest way is to use Excel. This is done by using a freebie macro PLX-DAQ, which essentially makes Excel into a terminal. You send it data just like you send it to the serial monitor, and Excel does the rest. This gives you either a live graph or a spreadsheet from which you can derive a graph later. Traffic is one-way

Any PC terminal programme can read and store the data for subsequent graphic presentation, and traffic is two-way. The advantage of Excel is that you get the graph live.

Similarly, you can send the data to an internet service like Xively, they do the rest, and the whole world gets to have look.

You may also use Processing live to good effect:
http://forum.arduino.cc/index.php?topic=194174.0

I have never done it myself but I understand it is a case of you send the data, we do the rest.

Needless to say, all the above measures provide their own date/time stamping.

I also use a graphic terminal on the phone. You send it data just like you send it to the serial monitor - again - but it goes out via bluetooth and, (sigh) yes, the phone does the rest. This can handle up to three sensors simultaneously. This is volatile but the data that made it need not be.

Another option is to draw the graph onto LCD for local display. Some pictures are at
Graph drawing from array woes. (SOLVED) - #4 by Nick_Pyner - Programming Questions - Arduino Forum.

It is routine to locally back up the data to SD and this can be subsequently transferred to Excel for graphic presentation.

I have no idea what PHP means, but maybe it is starting to sound like an option of last resort.

Hi thanks for your reply. Yeah i know processing i have already used it but this time i should display my data on the internet thanks to the ethernet shield so i can't use terminal.my ethernet shield is used as web server, i access to it and read the data and the graph. What should i use? Thanks.

Xively.

If you've got it, flaunt it.,

Hi man , thanks for your reply but i can't access to internet and therefore to Xively.com , i was thinking to some like this Temperature Sensing with Arduino, PHP and jQuery | Scouris's Arduino Adventures Do you know that?

my ethernet shield is used as web server

In reply #2 you implied you want to display your data on the internet via an ethernet shield, thereby excluding the use of processing etc., and now you say you can't access the internet. I think you need to be clearer about your intentions, or did something dramatic happen in the last 6 hours or so?

As I said, I have no idea about PHP, and I'm afraid I really can't comment on the link you posted other than that it seems to confirm my suspicion that it is an utterly pointless exercise in re-inventing the wheel - likely resulting in a square one.

We do live in a changing world and, in trying to be fair to Mr Scouris, perhaps the most notable point in that article of his is the date of its publication.

hi, for "i can't access to internet and therefore to Xively.com " i mean that i'm working in local , i have my arduino , my arduino ethernet , my Raspberry used as server (in which there is the php script and the mysql database) and a simple switch with an access point incorporated. So i'm in a LAN and i want to display my data on the web server (my arduino ethernet) i mean that if i go to http://MYARDUINOIP/ I am in front of a page with a graph and with a table composed by the last temperature readings. That's what i mean. Sorry if i haven't explained it well.
I've found these libraries
http://www.pchart.net/ in PHP.
http://www.flotcharts.org/ in Javascript.

Yes, http://www.flotcharts.org/ is a great opensource javascript plotting library it is my favourite lib for drawing graphs, you can also draw realtime graphs with it, for example with PHP it is not possible (in such elegant way).

luigialab:
So i'm in a LAN and i want to display my data on the web server (my arduino ethernet)

OK. I assume you are doing that just for the intellectual exercise, and that is fair enough. I guess it is evident by now that you can do the job a lot easier, and probably better, by creating the display somewhere else - presumably in the place where you want to look at it. As it is, you probably have Arduino as a boy on a man's job, while the man is standing around with his hands in his pockets.

You had better call on somebody like Zoomkat, who is better qualified than me on matters LAN, I only use ethernet to talk to the world.

Yes man i know that in this way it is easier and that i don't use all the potential of Arduino but i will use in an exam at school so i just want to make it works.
Oroboss can you explain me something about that library? Some samples maybe? thanks guys.

Yes sure, you just need to send data for plotting to javascript in this case for flotcharts library and than it will make nice charts for you.

With sending data for flotcharts (javascript) I mean:

  1. you need to get/send them with (one) AJAX request for example whole file with temperature readings and than parse it with javascript to draw chart for you.

  2. or in realtime you need to use something like websockets to send new data to flotcharts periodically (lets say every 20ms)

a lot of examples are here: Flot Examples

or you can look on my not very ideal example but working here: solara.mooo.com
(it is not finished but when you click mpptMonitor you will see websockets + flotcharts in action)