我有如下数据:
store 1 Store 2
store_id walk-ins walk-ins
morning 20 25
noon 35 40
night 50 55
有 20 家商店要用图表堆叠每行的值。
Google Charts 文档告诉我数据数组如下所示:
var data = google.visualization.arrayToDataTable([
['Stores', 'Store 1', 'Store 2', 'Store 3', 'Store 4', ... ],
['morning', 10, 24, 20, 32, 18, 5, ...],
['noon', 16, 22, 23, 30, 16, 9, ...],
['night', 28, 19, 29, 30, 12, 13, ...],
]);
我正在通过 MySQL 脚本/服务器 PHP 脚本获取数据。 JSON 应该是什么样的? MySQL查询的json_encode($data)
返回如下;
[{"store_name":"Store 1","Time":"Morning","count":"17"}, ...]
但图表未加载并给我一条消息“表没有列
”。
我按如下方式加载 JSON:
var url = '/url/updatedata.php?var=querytype';
jQuery.getJSON( url, function(Json) {
// Create and populate the data table.
var data = new google.visualization.DataTable(Json);
....
堆积柱形图的 JSON 结构是什么?
谢谢!
最佳答案
我知道这是一篇旧文章,但如果有人需要,这里是 Jsondata 的格式,用于使用来自服务器代码的谷歌堆叠列。
{
"cols": [
{
"id": "",
"label": "title",
"pattern": "",
"type": "string"
},
{
"id": "",
"label": "A",
"pattern": "",
"type": "number"
},
{
"type": "string",
"role": "annotation",
"p": {
"role": "annotation"
}
},
{
"id": "",
"label": "B",
"pattern": "",
"type": "number"
},
{
"type": "string",
"role": "annotation",
"p": {
"role": "annotation"
}
},
{
"id": "",
"label": "C",
"pattern": "",
"type": "number"
},
{
"type": "string",
"role": "annotation",
"p": {
"role": "annotation"
}
},
{
"id": "",
"label": "D",
"pattern": "",
"type": "number"
},
{
"type": "string",
"role": "annotation",
"p": {
"role": "annotation"
}
}
],
"rows": [
{
"c": [
{
"v": "Categories",
"f": null
},
{
"v": "10",
"f": null
},
{
"v": "10",
"f": null
},
{
"v": "20",
"f": null
},
{
"v": "20",
"f": null
},
{
"v": "30",
"f": null
},
{
"v": "30",
"f": null
},
{
"v": "50",
"f": null
},
{
"v": "50",
"f": null
}
]
}
]
}
关于javascript - Google 图表堆积柱的 JSON 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23150757/