I am trying to render graphs using canvas.js. The charts need to be rendered from an external JSON source, which is hosted at this website
http://gsx2json.com/api?id=1vc7wCjNXK39HMEYDkOJRMhQGPJpxMu4MJgTsydyLats
The objective is to, graph a chart from 2 values in the JSON data (ie example, timestamp vs latitude)
This is the code, which I have so far:
$.getJSON("http://gsx2json.com/apiid=1vc7wCjNXK39HMEYDkOJRMhQGPJpxMu4MJgTsydyLats", function addData(data){
for (var i = 0; i < data.length; i++) {
dataPoints.push({
x: new Date(data[i].columns["timestamp"]),
y: data[i].columns["latitude"]
});
}
chart.render();
// console.log(data.columns["timestamp"])
});
I am using the for loop to iterate thru the JSON object and then using JSON keys to access the data.
The data doesn't render, when I run this code. But, when I try to console.log (data.columns["latitude"]) outside the for-loop, I am able to access the data which I need.
Any help is much appreciated.
Thanks.
let iinstead ofvar iin your for loop declarationdataPointsdefined in your code?