I have a JavaScript function that loads a csv file and pastes its content to a c3js graph and the function reloads every 10 seconds for real time data, it looks something like this:
function parseData(createGraph) {
Papa.parse("../csv_files/traffic.csv", {
download: true,
complete: function(results) {
createGraph(results.data);
}
});
}
function createGraph(data) {
var Arrx = ['x'];
var Arry = ['Frequency'];
var dates = [];
for (var i = 0; i < data.length-1; i++) {
if(moment(data[i][0], "DD-MM-YYYY", true).isValid()){
dates.push(data[i][0]);
}
}
var result = foo(dates);
for (var i = 0; i < result[0].length; i++){
Arrx.push(result[0][i]);
Arry.push(result[1][i]);
}
var chart = c3.generate({
size: {
width: 1050
},
data: {
x: 'x',
xFormat: '%d-%m-%Y',
columns: [Arrx,Arry]
},
axis: {
x: {
label: 'Date',
type: 'timeseries',
tick: {
format: '%d-%m-%Y'
}
},
y: {
label: 'Frequency'
}
},
bindto: '#chart'
});
}
The problem is that I have to load the file at every reload and it's starting to take more and more time as the file gets bigger, is there a way in JavaScript to only load it once in the beginning and then append new logs to the graph in real-time?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment