I have a csv file :
title,number1,number2
M,12,22
T,17,27
W,7,17
T,17,27
F,23,33
And I want something written in this format in my js file because the rest of the program use datas with this format. It will be hard to modify all the code. I prefer to work on csv transform.
dataDailySalesChart = {
labels: ['M', 'T', 'W', 'T', 'F'],
series: [
[12, 17, 7, 17, 23],
[22, 27, 17, 27, 33]
]
};
I tried this code but it didn't work :
$(document).ready(function() {
$.ajax({
type: "GET",
url: "test.csv",
dataType: "text",
success: function(data) {processData(data);}
});
});
function processData(allText) {
var allTextLines = allText.split(/\r\n|\n/);
var headers = allTextLines[0].split(',');
var serie1 = allTextLines[1].split(',');
var serie2 = allTextLines[2].split(',');
var seriesTest = [serie1,serie2];
dataDailySalesChart = {
labels: headers,
series: seriesTest
};
}
But I have the error :
jquery-3.1.0.min.js:4 XMLHttpRequest cannot load file: test.csv. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https
Do you know why I get this error ?