Chart update - only update the chart data instead of the whole view

This commit is contained in:
petitPapillon 2017-12-14 23:09:38 +01:00
parent 28c39a4d2c
commit 5776614fe1
1 changed files with 39 additions and 23 deletions

View File

@ -1,4 +1,3 @@
var Refresh_active_StockChart_Interval = null; var Refresh_active_StockChart_Interval = null;
var gChart; var gChart;
@ -197,7 +196,7 @@ function UpdateDexChart(chartbase, chartrel) {
} }
//gChart.showWaitingBar(); //gChart.showWaitingBar();
clearChartData(); //clearChartData();
gChart.update(); gChart.update();
var userpass = sessionStorage.getItem('mm_userpass'); var userpass = sessionStorage.getItem('mm_userpass');
@ -223,28 +222,45 @@ function UpdateDexChart(chartbase, chartrel) {
}); });
} }
function parseBars(data, isIntraday) { function parseBars(data, isIntraday) {
var dataSeries = gChart.barDataSeries(); var dataSeries = gChart.barDataSeries();
//data.reverse(); //data.reverse();
gChart.showWaitingBar(); gChart.showWaitingBar();
$.each(data, function(index,value) { var newBars = [];
//console.log(index); $.each(data, function (index, value) {
//console.log(value); var time = new Date(value[0] * 1000);
var time = new Date( value[0] *1000);
//console.log(time);
dataSeries.date.add(time); if (dataSeries.date.values.length < index) {
dataSeries.open.add(parseFloat(value[1])); // if the data received from the API call contains more bars than the chart currently has
dataSeries.high.add(parseFloat(value[2])); // those bars should be appended to the chart
dataSeries.low.add(parseFloat(value[3])); var newBar = {
dataSeries.close.add(parseFloat(value[4])); 'date': time,
dataSeries.volume.add(parseInt(value[5], 10)); 'open': parseFloat(value[1]),
'high': parseFloat(value[2]),
'low': parseFloat(value[3]),
'close': parseFloat(value[4]),
'volume': parseInt(value[5], 10),
};
newBars.push(newBar);
} else {
// if the bar already exists, just update the data
dataSeries.date.values[index] = time;
dataSeries.open.values[index] = parseFloat(value[1]);
dataSeries.high.values[index] = parseFloat(value[2]);
dataSeries.low.values[index] = parseFloat(value[3]);
dataSeries.close.values[index] = parseFloat(value[4]);
dataSeries.volume.values[index] = parseInt(value[5], 10);
}
});
}); if (newBars.length > 0) {
gChart.updateComputedDataSeries(); gChart.appendBars(newBars);
gChart.update(); }
gChart.hideWaitingBar();
gChart.setNeedsAutoScaleAll();
gChart.updateComputedDataSeries();
gChart.update();
gChart.hideWaitingBar();
} }