Google图表错误-数据表无列

时间:2019-06-14 14:25:36

标签: javascript charts datatable literals

我正在从服务器中提取一些数据,它的格式似乎正确-但我似乎无法让Google Chart对象识别列。

代码是从一个大表生成的-但是即使将行和列的数量减少到一个小的测试集,我仍然会收到错误消息。

使用jQuery捕获数据并为图表定义如下:

var data = new google.visualization.DataTable(jsonData);

有人可以注意到我的错误吗?

谢谢!

{
  cols: [
              {id:"2",label:"ADL",type:"string"},
              {id:"3",label:"TOT",type:"number"},
              {id:"10",label:"CON",type:"number"},
              {id:"11",label:"SLS",type:"number"}
      ],
  rows: [
           {c:[
                    {v:"[FASHION/FINE/METAL/PREVIEW-ALL][20190517-20190615]"},
                    {v:19},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Intensive Landing: Fashion"},
                    {v:7},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Intensive Landing: Fine"},
                    {v:1},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Internet: Google"},
                    {v:1},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Internet: CHAT"},
                    {v:3},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Internet: Query"},
                    {v:1},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Referral: Saiman"},
                    {v:1},
                    {v:0},
                    {v:0.0000}
                  ]
           }
      ]
}

1 个答案:

答案 0 :(得分:0)

以下是使用您的数据的有效小提琴:https://jsfiddle.net/f9sz2nmx/1

dataTable = new google.visualization.DataTable(jsonData);
options = { /* options */ };
chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(dataTable, options);