使用 Google 图表传递数据
Passing data with Google Charts
我正在尝试使用 Google 图表传递数据,但我在控制台中收到一个错误,显示为 "Uncaught Error: Every row given must be either null or an array."
我已经在 Whosebug 上找到了这个 post,但它似乎并不适用。 Dynamic data with Google Charts。我的代码如下。
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
{"somePercentage":"3.44","someId":"VZ"
},
{"somePercentage":"6.95","someId":"XOM"
},
{"somePercentage":"5.55","someId":"GG"
},
{"somePercentage":"10.53","someId":"INTC"
},
{"somePercentage":"8.39","someId":"TD"
},
{"somePercentage":"5.59","someId":"VOD"
},
{"somePercentage":"12.67","someId":"ARII"
},
{"somePercentage":"17.73","someId":"VVVVA"
},
{"somePercentage":"21.81","someId":"BSV"
},
{"somePercentage":"7.34","someId":"VNM"}
]);
我做错了什么?
好吧,看起来您正在添加对象作为您的行。
如果你这样做会怎样
data.addrows([
["3.44", "VZ"],
["6.95", "XOM"],
...
]);
我正在尝试使用 Google 图表传递数据,但我在控制台中收到一个错误,显示为 "Uncaught Error: Every row given must be either null or an array."
我已经在 Whosebug 上找到了这个 post,但它似乎并不适用。 Dynamic data with Google Charts。我的代码如下。
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
{"somePercentage":"3.44","someId":"VZ"
},
{"somePercentage":"6.95","someId":"XOM"
},
{"somePercentage":"5.55","someId":"GG"
},
{"somePercentage":"10.53","someId":"INTC"
},
{"somePercentage":"8.39","someId":"TD"
},
{"somePercentage":"5.59","someId":"VOD"
},
{"somePercentage":"12.67","someId":"ARII"
},
{"somePercentage":"17.73","someId":"VVVVA"
},
{"somePercentage":"21.81","someId":"BSV"
},
{"somePercentage":"7.34","someId":"VNM"}
]);
我做错了什么?
好吧,看起来您正在添加对象作为您的行。
如果你这样做会怎样
data.addrows([
["3.44", "VZ"],
["6.95", "XOM"],
...
]);