javascript - 使用 Google Charts 传递数据

标签 javascript json google-visualization

我尝试使用 Google Charts 传递数据,但在控制台中收到错误消息“ Uncaught Error :给定的每一行必须为 null 或数组。”

我已经在 stackoverflow 上找到了这篇文章,但它似乎不适用。 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"],
    ...
]);

关于javascript - 使用 Google Charts 传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30462205/

相关文章:

javascript - setState 回调函数没有被调用?

javascript - 如何最好地使用 Git 共享 QooXDoo?

mysql - 在 Laravel 中从 MySQL 字段插入和检索信息

json - 为什么在postgreSQL中不能将NULL转成JSON的null?

json - 格式化大型JSON文件的最佳方法? (〜30 mb)

jquery - 图例和 google vis 之间的边距。图表

javascript - AngularJS 范围.$watch btn 触发器

javascript - 多个 $scope.$watch 在 Angular JS 中不起作用

javascript - 如何使用 google 图表使用来自 json 的动态数据

javascript - 如何获取线条标签值(Google Charts)