I'm trying to integrate Chart JS into a project. I have some JSON data that is returned via Ajax using the following:
$(".symptom-graph").each(function(){
Tygh.$.ceAjax(
'request',
fn_url('symptom_tools.ajax_symptom_graph'),
{
data:{
symptom_ids: $(this).data('symptom-id')
},
callback: function(data) {
$(".symptom-graph").each(function(){
if($(this).data('symptom-id') == data['symptom_ids'])
{
//TODO: load up graph stuff here
$(this).html(data['graph_data']);
}
});
}
}
);
});
The above code returns the following JSON data:
[{
"x": "0",
"y": "35"
}, {
"x": "1",
"y": "6"
}, {
"x": "2",
"y": "3"
}, {
"x": "3",
"y": "11"
}, {
"x": "4",
"y": "2"
}]
I'm trying to access each item in the array and pull out either the X or Y coordinate so that the data: []
array in my Chart JS script has the each of the items.
I've tried the following to access either the Y or X coordinate:
data['graph_data']['0']['y']
data['graph_data'][0]['y']
data['graph_data']['y']
data['graph_data'][0]
Not sure how I'd loop over each one either.
Any guidance/solutions would be helpful, thanks.