Google图表堆叠列的JSON格式

The*_*apa 3 javascript php charts json

我有如下数据:

           store 1   Store 2
store_id   walk-ins  walk-ins
morning      20        25
noon         35        40
night        50        55
Run Code Online (Sandbox Code Playgroud)

图表堆叠每行的值有20个商店.

谷歌图表文档告诉我数据数组如下所示:

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, ...],
      ]);
Run Code Online (Sandbox Code Playgroud)

我通过My​​SQL脚本/服务器PHP脚本获取数据.JSON应该是什么样的?在json_encode($data) 从MySQL查询返回如下:

[{"store_name":"Store 1","Time":"Morning","count":"17"},...]

但图表没有加载并给我一条消息" Table has no columns".

我按如下方式加载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);
....
Run Code Online (Sandbox Code Playgroud)

堆积柱形图的JSON结构是什么?

谢谢!

Har*_*560 5

我知道这是一个旧帖子,但如果有人需要它,这里是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
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)