I've been trying to parse a CSV file with Papaparse4 to use it on charts created with C3js, but I can't get it to work.
I want to be able to load different CSV files, so I'm using a file input, the file gets parsed (I can see it on the console), but I can't load the data to the chart.
You can test it here: http://jsfiddle.net/Honzo_Nebro/mv6eomf4/
function handleFileSelect(evt) {
var file = evt.target.files[0];
Papa.parse(file, {
header: true,
dynamicTyping: true,
complete: function(results) {
data = results;
console.log(data);
var chart = c3.generate({
bindto: '#chart',
size: {
height: 359
},
json: data,
});
}
});
}
$(document).ready(function() {
$("#csv-file").change(handleFileSelect);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" id="csv-file" name="files" />
<div id="chart"></div>