[英]destroy multiple charts on same page
我正在使用Angularjs創建項目。 在我的項目中,我使用angularcharts.js集成了圖表,在我的項目中,在同一頁面上顯示了兩個圖表。 我想在用戶更改選擇選擇框上的某些文件時銷毀兩個圖表,但是我無法做到這一點。 這是我的代碼:在js中:
$scope.$on('create', function(event, chart) {
console.log(chart)
$rootScope.checkgraph = chart;
});
if($scope.allFlows.length == 0)
$scope.checkgraph.destory()
}
在HTML中:
<canvas id="line" class="chart chart-line" chart-data="dataBilling"
chart-labels="labelsBilling" chart-colours="ocw.colours" chart-options="options" chart-legend="true"
chart-click="onClick" height="150" width="400">
</canvas>
<canvas id="line" class="chart chart-line" chart-options="options" chart-data="data"
chart-labels="labels" chart-colours="ocw.colours" chart-legend="true"
chart-click="onClick" height="150" width="400">
</canvas>
我過去曾做過類似的事情,如果我沒記錯的話,這就是我的做法:
在控制器中
$scope.charts = [
{
// chart 1 data
},
{
// chart 2 data
}
]
$scope.removeChart = function(index) {
$scope.charts.splice(index,1);
}
和html
<div ng-repeat="chart in charts track by $index">
<!-- charts come here -->
</div>
如果您從圖表數組中刪除圖表,它也會從前視圖中消失
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.