我正在使用 angular-chart.js ( http://jtblin.github.io/angular-chart.js/ ) 模块并尝试使用 UI-Grid 模块 ( http://ui-grid.info ) 使图表数据可编辑/docs/#/tutorial/201_editable)。我能够编辑数据,但不确定如何在编辑单元格时响应更新图表。我正在为此抗争一段时间。我会很感激对此的任何想法。
这是我到目前为止所得到的:
app.controller("myController", function ($scope) {
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Series A', 'Series B'];
$scope.gridOptions = {
columnDefs: [
{ name: 'A', width: '50%', enableCellEdit: true },
{ name: 'B', width: '50%', enableCellEdit: true }
],
data: [{
"A": 65,
"B": 28
},
{
"A": 59,
"B": 48
},
{
"A": 80,
"B": 40
},
{
"A": 81,
"B": 19
},
{
"A": 56,
"B": 86
},
{
"A": 55,
"B": 27
},
{
"A": 40,
"B": 90
}
]
};
var seriesA = [];
for (var i = 0; i < $scope.gridOptions.data.length; i++) {
seriesA.push($scope.gridOptions.data[i].A);
}
console.log(seriesA);
var seriesB = [];
for (var i = 0; i < $scope.gridOptions.data.length; i++) {
seriesB.push($scope.gridOptions.data[i].B);
}
console.log(seriesB);
$scope.data = [
seriesA,
seriesB
];
$scope.onClick = function (points, evt) {
console.log(points, evt);
};
});
这是 HTML 片段:
<div id="grid1" class="panel" ui-grid="gridOptions" ui-grid-edit ui-grid-row-edit ui-grid-cellNav class="grid"></div>
<canvas id="line" class="chart chart-line" data="data"
labels="labels" legend="true" series="series"
click="onClick"></canvas>