编辑:我正在寻找下面布局中的一个例子。我可能会遗漏一些东西,因为这是我第一次使用Google Charts ...感谢您的帮助!
{
"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!有人能指出我可能存在的一个例子,我已经错过了。谢谢你的帮助。
答案 0 :(得分:0)
您检查了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"]
]