简体   繁体   English

Google Charts JSON格式的条形图

[英]Google charts JSON format for stacked bar chart

EDIT: I am looking for an example in the layout below. 编辑:我正在下面的布局中查找示例。 I may be missing something as this is my first time with Google Charts... Thanks for the help! 我可能是缺少某些东西,因为这是我第一次使用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'}]},...
      ]
}

I cannot find anywhere an example of how the JSON record needs to be formatted for a stacked bar chart for Google Charts. 我找不到任何示例说明如何为Google图表的堆叠条形图格式化JSON记录。 I have tried a few combinations but I am struggling visualising it. 我尝试了几种组合,但是我正在努力使其形象化。

My data contains: 我的数据包含:

           Store 1   Store 2
store_id   walk-ins  walk-ins
morning      20        25
noon         35        40
night        50        55

There are 20 stores to chart stacking the values of each row. 有20个存储库,以图表方式堆叠每行的值。

My JSON right now looks like: 我的JSON现在看起来像:

[{"store_id":"Store 1","time":"morning","walk-ins":"20"}, and so on...]

I am happy to share the PHP once I work out what it needs to format the record like! 一旦确定了格式化记录的格式,我将很高兴分享PHP! Can someone point me to an example that may exist that I have missed please. 有人可以指出一个我可能错过的例子吗? Thanks for any help. 谢谢你的帮助。

Have you checked the Documentation ? 您是否检查过文档

The JSON format seems to be an array of arrays : JSON格式似乎是一个数组数组:

 var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses'],
          ['2004',  1000,      400],
          ['2005',  1170,      460],
          ['2006',  660,       1120],
          ['2007',  1030,      540]
        ]);

that means your data would look like this: 这意味着您的数据将如下所示:

[
    ["store_id", "time","walk-ins"],
    ["Store 1","morning","30"],
    ["Store 2","afternoon","40"],
    ["Store 3","night","50"]
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM