Having some trouble creating a chart using CanvasJS.
After fetching data from the API and checking the JSON array, I encounter two errors when attempting to generate dataPoints for the graph: "data invalid" on the data field and "NaN" on the value field.
Any suggestions or hints would be greatly appreciated!
// Retrieving data
fetch('https://example.com/my/endpoint').then(response => {
return response.json();
}).then(data => {
// Process JSON data here
var jsonData = data;
// Creating Data Points
var dataPoints = [];
for (var i = 0; i <= jsonData.length - 1; i++) {
dataPoints.push({ y: new Date(jsonData[i].source_ts), x: Number(jsonData[i].xyzw) });
console.log(dataPoints);
}
var chart = new CanvasJS.Chart("chartContainer", {
data: [
{
dataPoints: dataPoints,
type: "line",
}
]
});
chart.render();
}).catch(err => {
throw new Error( 'Failed to retrieve data' );
});
Cheers