我正在使用 Angular 图表,并且我正在尝试显示一个根据所选当前项目进行更新的图表,它在我选择的第一个项目上运行良好,但在我选择第二个项目后,似乎数据从所选的第一个项目仍然出现在图表上(尽管数据已完全更改),问题如下所示:
app.controller("itemsAppController", function ($scope, $timeout, itemsData, itemsFactory, $filter) {
$scope.items = itemsData.Items;
$scope.itemSelected = false;
$scope.currentItem = {};
$scope.selectItem = function (itemId) {
$scope.itemSelected = false;
var foundItem = $filter('filter')($scope.items, { ItemId: itemId }, true);
var item = foundItem[0];
$scope.currentItem = item;
$timeout(function () {
$scope.itemSelected = true;
}, 500);
};
$scope.chartOptions = {
tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>%"
}
});
Canvas :
<div ng-show="itemSelected">
<canvas class="chart chart-pie" data="currentItem.MostUsedChampionsPrePatchData" labels="currentItem.MostUsedChampionsPrePatchLabels" legend="true" options="chartOptions"></canvas>
</div>
对象数据如下所示:
对于导致此问题的原因有什么想法吗?
编辑:这是一个显示问题的 fiddle :https://jsfiddle.net/PGjtS/130/
重新创建它时,当我包含动画和 ng-show 时出现问题
最佳答案
关于javascript - AngularJS 图表未正确更新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32174250/