I probably didn't phrase the question well
I am a newbie in json code and I need to create a graph on canvas with javascript. The queries in php and mysql are carried out correctly and I perfectly convert the results into an array and this into json code to work with the results in a javascript file.
I am using the Chart Js framework to create the charts. My conflict is in this part, where it is manually completed like this
labels: ["month1", "month2"], data: [500, 550],
now the data of labels and data I get from a sql query
I have the following code
var nom = '';
for(var i in d2){
nom += '"'+d2[i].N+'",';
}
nom = nom.substring(0,nom.length-1);
var punto = '';
for(var j in d2){
punto += d2[j].P+',';
}
punto = punto.substring(0,punto.length-1);
The error occurs when I pass these variables to the corresponding data, that is:
labels: [nom],
data: [punto],
When executing the code, I take each variable as a single string, and I need it to take them as several values separated by commas. I don't know what type of conversion I should do.
It takes them as strings, because you are defining them as strings. Chart.js expects those values as arrays, so change your code to use arrays.
And you use them as is: