如何从mysql数据创建图表? (使用谷歌可视化API)
我有一些数据,想要创建一些动态图表。我看过 Google 可视化 api ..它看起来很棒,但问题是我对它不是很熟悉。任何想法,我如何从 mysql 数据设置 data.setValue
。
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geomap']});
google.setOnLoadCallback(drawMap);
function drawMap() {
var data = new google.visualization.DataTable();
data.addRows(6);
data.addColumn('string', 'Country');
data.addColumn('number', 'Popularity');
data.setValue(0, 0, 'Germany');
data.setValue(0, 1, 200);
data.setValue(1, 0, 'United States');
data.setValue(1, 1, 300);
data.setValue(2, 0, 'Brazil');
data.setValue(2, 1, 400);
data.setValue(3, 0, 'Canada');
data.setValue(3, 1, 500);
data.setValue(4, 0, 'France');
data.setValue(4, 1, 600);
data.setValue(5, 0, 'RU');
data.setValue(5, 1, 700);
var options = {};
options['dataMode'] = 'regions';
var container = document.getElementById('map_canvas');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
};
</script>
我可以使用其他一些方法创建图表,但只是对使用 Google Visualization API 感兴趣。
谢谢。
I have some data and want to create some dynamic charts. I have looked on Google visualisation api .. It looks great but the problem is I am not very familiar with it. Any ideas, how I can set the data.setValue
from mysql data.
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geomap']});
google.setOnLoadCallback(drawMap);
function drawMap() {
var data = new google.visualization.DataTable();
data.addRows(6);
data.addColumn('string', 'Country');
data.addColumn('number', 'Popularity');
data.setValue(0, 0, 'Germany');
data.setValue(0, 1, 200);
data.setValue(1, 0, 'United States');
data.setValue(1, 1, 300);
data.setValue(2, 0, 'Brazil');
data.setValue(2, 1, 400);
data.setValue(3, 0, 'Canada');
data.setValue(3, 1, 500);
data.setValue(4, 0, 'France');
data.setValue(4, 1, 600);
data.setValue(5, 0, 'RU');
data.setValue(5, 1, 700);
var options = {};
options['dataMode'] = 'regions';
var container = document.getElementById('map_canvas');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
};
</script>
I can create chart using some other methods but just interested in using Google Visualisation API.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我推荐 http://pchart.sourceforge.net/ pchart 进行绘图。它工作得很好。
i recommend http://pchart.sourceforge.net/ pchart for graphing. it works perfectly.
更新:
了解如何向图表添加数据。您可以添加 JSON 格式的数据。
您唯一要做的就是准备一个相应的 PHP 数组。然后你可以序列化这个数组并设置数据。例如,
我建议阅读文档/API 参考。我基本上只是通过搜索发现了这一点...
没有进一步的信息,我们无法给出具体的答案,但一般方法是:
假设您已经从结果集中的数据库中获取了记录
$results
,而不是您可以循环它:Update:
Have a look at how you can add data to the chart. You have the possibility to add data in JSON.
The only thing you have to do is to prepare a corresponding PHP array. Then you can serialize this array and set the data. E.g.
I recommend to read the documentation / API reference. I basically found this just by searching...
Without further information we cannot give a specific answer but a general approach is:
Assuming that you already fetched the records from your DB in a result set
$results
than you can just loop over it: