views:

249

answers:

1

Hi I have a query that I have run with MySql and I need to chart the data. I would be grateful if someone can tell me how I can format the output using php and feed it to Google in the right way and with the syntax - I have tried everything but no joy.

A code sample would be really useful if possible. Ideally I would like a line chart that has as its X axis the time and it's Y axis the # of questions.

hour    questions
0   27
1   28
2   15
3   16
4   16
5   16
6   22
7   19
8   42
9   24
10  38
11  21
12  33
13  25
14  21
15  16
16  12
17  11
18  5
19  8
20  2

Thanks in anticpation of your help.

Kind regards

Jonathan

+2  A: 

Like this:

Data returned from the query, in a table:
fulldate              hour       handheld   website   irma      hoc_client spreadsheet
2009-10-14 23:00:00   23         93         2         1         0          0
2009-10-15 00:00:00   00         15         1         2         0          0
2009-10-15 01:00:00   01         61         0         0         0          0
2009-10-15 02:00:00   02         25         2         0         0          0
2009-10-15 03:00:00   03         39         0         0         0          0
2009-10-15 04:00:00   04         91         5         1         0          0
2009-10-15 05:00:00   05         239        13        1         0          0
2009-10-15 06:00:00   06         443        14        14        0          0
2009-10-15 07:00:00   07         568        23        11        0          0
2009-10-15 08:00:00   08         613        37        59        0          0
2009-10-15 09:00:00   09         834        30        60        0          0
2009-10-15 10:00:00   10         1026       50        35        0          0
2009-10-15 11:00:00   11         938        62        45        0          0
2009-10-15 12:00:00   12         794        72        58        0          0
2009-10-15 13:00:00   13         708        71        39        0          0
2009-10-15 14:00:00   14         618        54        32        0          0
2009-10-15 15:00:00   15         336        64        14        0          0
2009-10-15 16:00:00   16         216        50        15        0          0
2009-10-15 17:00:00   17         225        24        6         0          0
2009-10-15 18:00:00   18         148        20        5         0          0
2009-10-15 19:00:00   19         182        9         4         0          0
2009-10-15 20:00:00   20         153        6         5         0          0
2009-10-15 21:00:00   21         102        2         1         0          0
2009-10-15 22:00:00   22         90         5         3         0          0
2009-10-15 23:00:00   23         56         3         3         0          0


The same data as a call to the chart api:
http://chart.apis.google.com/chart
?cht=bvs
&chtt=DVO Orders Per Hour
&chbh=a,1,3
&chs=700x200
&chxt=x,y
&chds=0,2000
&chxr=1,0,2000
&chco=FF0000,00C000,0000FF,FFFF00,9B30FF,EE00EE,000000,00F5FF,54FF9F,C0FF3E,FFC125
&chdl=Handheld|Website|IRMA|HOC Client|Spreadsheet
&chxl=0:|23|00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23
&chd=t:93,15,61,25,39,91,239,443,568,613,834,1026,938,794,708,618,336,216,225,148,182,153,102,90,56|2,1,0,2,0,5,13,14,23,37,30,50,62,72,71,54,64,50,24,20,9,6,2,5,3|1,2,0,0,0,1,1,14,11,59,60,35,45,58,39,32,14,15,6,5,4,5,1,3,3|0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0|0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

That's a barchart, they vary a bit for different chart types - but it's very literal .. no "range calculations" done for you like in Excel.

In Perl, I loop through the query result values and build strings to fill the various GAPI chart values.

Your data would be built into a string like:

http://chart.apis.google.com/chart
?cht=bvs
&chtt=My Spiffy Data
&chs=700x200
&chxt=x,y
&chds=0,40
&chxr=1,0,40
&chco=FF0000
&chdl=Data
&chxl=0:|0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20
&chd=t:27,28,15,16,16,16,22,19,42,24,38,21,33,25,21,16,12,11,5,8,2

Ron

Ron Savage
Thanks Ron - that helps enormously, I really get it now. I guess the thing I'm struggling with now is how to get the data from my MySQL query using PHP into the format needed (in essence , build the data strings for the x and y values). As you can see from my example I only have one data series(questions) and one x series (hours). Any ideas on how I could take the query and transpose it / write it the necessary way?
Jonathan Lyon