I am working on a small project where I feed a data directory with some csv and expect my webview (html/css/js) page to be refreshed with new charts.
Generating chart view is fairly easy when I specify the file I want to parse, but I struggle on looping on files in my data directory.
I run "python -m http.server" as my localhost server so don't have access to node.js/fs
| data
| | file1.csv
| | file2.csv
| | filen.csv
| js
| css
| index.html
My Javascript code
function parseData(createGraph, filePath) {
Papa.parse("filePath", {
download: true,
complete: function(results) {
console.log(results.data);
// createGraph(results.data);
genericGraph(results.data);
}
});
}
function genericGraph(data) {
var xaxis = [];
var yaxis = [];
for (var i = 1; i < data[0].length; i++) {
yaxis.push([data[0][i]])
}
for (var i = 1; i < data.length - 1; i++) {
for (var j = 0; j < yaxis.length; j++) {
yaxis[j].push(data[i][j + 1])
}
xaxis.push(data[i][0])
}
console.log(xaxis)
console.log(yaxis)
var chart = c3.generate({
bindto: '#chart',
data: {
columns: yaxis
},
axis: {
x: {
type: 'category',
categories: xaxis,
tick: {
multiline: false,
rotate: 60,
culling: {
max: 10
}
}
}
},
zoom: {
enabled: true
},
legend: {
position: 'right'
}
});
}
function loopThroughFiles()
{
var files = [] // How to get the list of files under "../data"?
files.foreach(file=>
parseData(genericGraph, file);
)
}