如何使用谷歌图表api绘制此数据?

时间:2009-10-17 04:23:27

标签: php charts google-visualization

您好我有一个我用MySql运行的查询,我需要绘制数据图表。如果有人可以告诉我如何使用php格式化输出并以正确的方式将其提供给Google并使用语法,我将不胜感激 - 我已经尝试了所有内容,但没有任何乐趣。

如果可能,代码示例将非常有用。理想情况下,我想要一个折线图,其X轴为时间,Y轴为问题#。

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

感谢你的帮助。

亲切的问候

乔纳森

1 个答案:

答案 0 :(得分:3)

像这样:

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

这是一个条形图,它们对于不同的图表类型有所不同 - 但它非常直观..没有为Excel做过的“范围计算”。

在Perl中,我遍历查询结果值并构建字符串以填充各种GAPI图表值。

您的数据将构建为如下字符串:

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