Reputation: 324
I use Google chart for create chart. But I have a problem. Now I have a chart, created like this (Example in page ofgoogle chart):
/* 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'
};
});
If I would like modified that chart adding a row, how can I do?
I would add "apple" so $scope.chartObject.data
will be:
$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},
]}
]};
Anyone can tell me how I can add "Apple" by code? I supposed that there is a method like addRow or something like this.
Upvotes: 0
Views: 209
Reputation: 722
You could do it with Push()
as below.
var newC = {c: [
{v: "Apple"},
{v: 7},
]};
$scope.chartObject.data.rows.push(newC);
Upvotes: 2