编辑:我正在寻找下面布局中的示例。我可能错过了一些东西,因为这是我第一次使用 Google 图表...感谢您的帮助!
{
"cols": [
{"id":"","label":"Store 1","pattern":"","type":"number"},
{"id":"","label":"Store 2","pattern":"","type":"number"},
{"id":"","label":"Store 3","pattern":"","type":"number"},...
],
"rows": [
{"c":[{"v":"morning","f":'15'},{"v":"noon","f":'20'},{"v":"night","f":'25'}]},...
]
}
我在任何地方都找不到关于如何为 Google Charts 的堆叠条形图格式化 JSON 记录的示例。我尝试了几种组合,但我很难想象它。
我的数据包含:
Store 1 Store 2
store_id walk-ins walk-ins
morning 20 25
noon 35 40
night 50 55
有 20 个商店可以用图表堆叠每行的值。
我的 JSON 现在看起来像:
[{"store_id":"Store 1","time":"morning","walk-ins":"20"}, and so on...]
一旦我弄清楚了需要什么来格式化记录,我很乐意分享 PHP!有人可以指出我可能错过的一个可能存在的例子吗?感谢您的帮助。
最佳答案
您检查过Documentation吗? ?
JSON 格式似乎是数组的数组:
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
这意味着您的数据将如下所示:
[
["store_id", "time","walk-ins"],
["Store 1","morning","30"],
["Store 2","afternoon","40"],
["Store 3","night","50"]
]
关于javascript - Google 图表堆叠条形图的 JSON 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23147288/