I need to create an array in javascript of the style var data = [1,2,3,4]; to represent that data on a canvas. The data would be collected from a file on the desktop with an input of the file type.
The content of the file would be:
1
2
3
4
How can I do it? Thanks in advance.
I have this code in which I read the contents of the file, but I do not parse it to the data array.
var datos = [1,1,10,1,1,1,1,1];
function processFiles(files) {
var file = files[0];
var reader = new FileReader();
reader.onload = function (e) {
var output = document.getElementById("fileOutput");
output.textContent = e.target.result;
};
reader.readAsText(file);
var ctx = document.getElementById("grafico").getContext("2d");
var lineChartData = {
labels: ["0ms", "50ms", "100ms", "150ms", "200ms", "250ms", "300ms", "350ms"],
datasets: [
{
label: ' miliVoltios',
fillColor: "rgba(20,20,220,0.2)",
strokeColor: 'rgba(200,2,2,1)',
pointColor: "#1e45d7",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: datos,
borderWidth: 4
},
]
}
var options = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}],
}
};
window.myPie = new Chart(ctx).Line(lineChartData, {responsive: true}, {options: options});
}
<input id="fileInput" type="file" size="50" onchange="processFiles(this.files)">
<div id="fileOutput"></div>