0
저는 AngularJS 어플리케이션에서 AmCharts를 실시간으로 작업하고 있으며 데이터 포인트를 차트에 밀어 넣을 수있는 방법을 알고 싶었습니다. 내 컨트롤러의 코드는 다음과 같습니다.데이터 포인트를 실시간으로 푸는 방법 AmCharts
$http.get(hostNameService.getHostName()+"/dashboard/itemValue")
.then(function (response) {$scope.item = response.data.items;
function generateChartData(){
var chartData = [];
for (var i = 0; i < $scope.item.length; i++) {
var itemId = $scope.item[i].itemId;
var avail = $scope.item[i].itemAvailability;
chartData.push({
"itemId": itemId,
"avail": avail
});
}
return chartData;
}
/**
* Create the chart
*/
var chart = AmCharts.makeChart("toolAvailability", {
"type": "serial",
"theme": "light",
"zoomOutButton": {
"backgroundColor": '#000000',
"backgroundAlpha": 0.15
},
"dataProvider": generateChartData(),
"categoryField": "itemId",
"graphs": [ {
"id": "g1",
"valueField": "avail",
"bullet": "round",
"bulletBorderColor": "#FFFFFF",
"bulletBorderThickness": 2,
"lineThickness": 2,
"lineColor": "#b5030d",
"negativeLineColor": "#0352b5",
"hideBulletsCount": 50
} ],
"chartCursor": {
"cursorPosition": "mouse"
}
})
/**
* Set interval to push new data points periodically
*/
// set up the chart to update every second
setInterval(function() {
// normally you would load new datapoints here,
// but we will just generate some random values
// and remove the value from the beginning so that
// we get nice sliding graph feeling
// remove datapoint from the beginning
chart.dataProvider.shift();
// for (var i = 0; i < $scope.item.length; i++) {
// var itemId = $scope.item[i].itemId;
// var avail = $scope.item[i].itemAvailability;
// }
chart.dataProvider.push({// not sure how I can push the json data here
date: //need to push the value here,
visits: //need to push the value here
});
chart.validateData();
}, 1000);
});
내 차트가 웹 서비스에서 데이터를 가져 오는 중입니다. 웹 서비스는 10 개의 항목을 반환하며 각 항목의 가용성은 실시간으로 업데이트되어야합니다. 차트에서 itemId 및 사용 가능성을 사용하고 있습니다. 처음에는 차트에 데이터를로드 할 수있었습니다. 그러나 차트가 한 값을 이동할 때 어떻게 새로운 값을 밀어 넣어야합니까? 아무도 내가이 기능을 달성 할 수있는 방법을 알려주십시오 수 있습니다.