【发布时间】:2017-06-19 08:28:12
【问题描述】:
我正在使用 D3 图表在屏幕上显示数据。数据从 WebApi 更新。数据更新后,我想刷新图表中的数据。
这里是代码
$scope.config = {
title: 'Products',
tooltips: true,
labels: false,
mouseover: function () { },
mouseout: function () { },
click: function () { },
legend: {
display: true,
//could be 'left, right'
position: 'right'
}
};
$http.put(WebApiURL.GetWebApiURL() + 'api/ReportPerformance', data)
.then(function (response) {
$scope.PerformanceData = response.data;
$scope.LoadingData = "";
$scope.chartdata = [];
var tempchartdata = [];
angular.forEach($scope.PerformanceData, function (value) {
tempchartdata.push(value.ReportTimeInSeconds);
});
$scope.chartdata = tempchartdata;
}), function errorCallback(x, y, z) {
$scope.LoadingData = "Error while generating report:= " + x.ExceptionMessage;
};
}
此网络电话正在更新数据$scope.chartdata。
html中的图表定义...
<div data-ac-chart="'bar'"
data-ac-data="chartdata"
data-ac-config="chartConfig"
style="height: 500px; width: 500px;"
class="chart">
</div>
但是当数据来自 webApi 时,它正在更新 $scope.chartdata 但它没有反映在屏幕上。
添加了 plunker...http://plnkr.co/edit/a0mVRL0Jo9ah8Om8ONTc
【问题讨论】:
-
你能提供小提琴吗?
-
您需要将绘制/更新图表的代码放在
$http.put回调中,或者添加$scope.$watch并将其放在那里。你能展示实际制作图表的代码吗? -
这是绘制图表的实际代码。你能给我举一些例子来提供你的建议吗?
-
“这是绘制图表的实际代码”...你在说什么?该代码中没有一行 D3。
-
我就放弃了……
标签: javascript angularjs d3.js