Skip to content
Advertisement

Parse Uploaded CSV file using D3.js

I’m new to d3.js so I know this might seem as a silly question to some so please bear with me. I’m trying to parse a csv file which a user uploads and print it’s output in the console. I’m able to parse the CSV file when I provide the absolute path of the CSV file but when I try doing the same with file upload functionality I’m not getting any output in the console..

Working Javascript Code..

JavaScript

Console Output

JavaScript

New HTML code..

JavaScript

Modified Javascript Code(not working)..

JavaScript

Since there was no official documentation on how to handle user uploaded CSV file I can’t figure out where I’m going wrong..Is there a way I can use HTML5 file reader?? Please help..

Advertisement

Answer

You are close but you don’t need to and can’t call d3.csv on a reader.result. d3.csv makes an async AJAX call to retrieve a CSV file from a server. You already have the file contents and just want to parse, so use d3.csv.parse.

Full working example:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement