I stuck on the following thing. I don't have a running local http-service so I'd like to handle my file loading otherwise.
First I created the following function, as suggested in some references.
var fileArray = [];
function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files;
window.array = []
if (f) {
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
window.array.push(contents);
fileArray.push({name:f.name, contents: contents});
}
r.readAsText(f);
console.log(fileArray);
} else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
Then I try to call the fileArray in a d3.csv function. But this is where I stuck - the console log just shows an empty array.
var dataset = []
d3.csv(fileArray, function(data) {
dataset = data.map(function(d) { return [ d["TEXT"], +d["HOURS"], +d["MONTH_DIGIT"] ]; });
console.log(dataset)
});
The .csv file has the following structure.
"TEXT","HOURS","MONTH_DIGIT"
"Adjustments work",849.45,"01"
How do I exactly call the file to work with d3.js?