gpt4 book ai didi

javascript - 在谷歌图表AngularJS中添加行

转载 作者:行者123 更新时间:2023-12-02 15:14:11 24 4
gpt4 key购买 nike

我使用Google chart用于创建图表。但我有一个问题。现在我有一个像这样创建的图表(Google 图表页面中的示例):

/* global angular */
angular.module("google-chart-sample").controller("GenericChartCtrl", function ($scope, $routeParams) {
$scope.chartObject = {};

$scope.onions = [
{v: "Onions"},
{v: 3},
];

$scope.chartObject.data = {"cols": [
{id: "t", label: "Topping", type: "string"},
{id: "s", label: "Slices", type: "number"}
], "rows": [
{c: [
{v: "Mushrooms"},
{v: 3},
]},
{c: $scope.onions},
{c: [
{v: "Olives"},
{v: 31}
]},
{c: [
{v: "Zucchini"},
{v: 1},
]},
{c: [
{v: "Pepperoni"},
{v: 2},
]}
]};


// $routeParams.chartType == BarChart or PieChart or ColumnChart...
$scope.chartObject.type = $routeParams.chartType;
$scope.chartObject.options = {
'title': 'How Much Pizza I Ate Last Night'
};
});

如果我想修改该图表添加一行,我该怎么做?

我会添加“apple”,因此$scope.chartObject.data将是:

$scope.chartObject.data = {"cols": [
{id: "t", label: "Topping", type: "string"},
{id: "s", label: "Slices", type: "number"}
], "rows": [
{c: [
{v: "Mushrooms"},
{v: 3},
]},
{c: $scope.onions},
{c: [
{v: "Olives"},
{v: 31}
]},
{c: [
{v: "Zucchini"},
{v: 1},
]},
{c: [
{v: "Pepperoni"},
{v: 2},
]},
{c: [
{v: "Apple"},
{v: 7},
]}
]};

谁能告诉我如何通过代码添加“Apple”?我认为有一个像 addRow 这样的方法或类似的方法。

最佳答案

您可以使用 Push() 来完成此操作,如下所示。

var newC =  {c: [
{v: "Apple"},
{v: 7},
]};

$scope.chartObject.data.rows.push(newC);

关于javascript - 在谷歌图表AngularJS中添加行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34593804/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com