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,25 +222,42 @@ 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);
dataSeries.open.add(parseFloat(value[1]));
dataSeries.high.add(parseFloat(value[2]));
dataSeries.low.add(parseFloat(value[3]));
dataSeries.close.add(parseFloat(value[4]));
dataSeries.volume.add(parseInt(value[5], 10));
if (dataSeries.date.values.length < index) {
// if the data received from the API call contains more bars than the chart currently has
// those bars should be appended to the chart
var newBar = {
'date': time,
'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.appendBars(newBars);
}
gChart.setNeedsAutoScaleAll();
gChart.updateComputedDataSeries(); gChart.updateComputedDataSeries();
gChart.update(); gChart.update();
gChart.hideWaitingBar(); gChart.hideWaitingBar();