Reputation: 11
generate.php will extract data from mysql in json
format.
then graph.php will request to generate.php through ajax
for the json
data.
how can i use this json
data to feed dygraph
data,
example dygraph code.
g3 = new Dygraph(
document.getElementById("graphdiv3"),
//"temperatures.csv",
[ //this part i need to change with ajax request data
[1,10,100],
[2,20,80],
[3,50,60],
[4,70,80]
],
//jsonStr,
//data;
{
rollPeriod: 7,
showRoller: true
}
);
Upvotes: 1
Views: 2018
Reputation: 1325
A bit late to this answer, but just wrap the AJAX call around the Dygraph declaration (jQuery assumed here)
$.getJSON('data.json', function (data) {
var g = new Dygraph(document.getElementById("graphdiv"), data.rows,
{
//options
});
})
// AJAX callbacks
.done(function() { console.log('getJSON request succeeded!'); })
Upvotes: 1
Reputation: 16905
You can use the file
option to updateOptions
to change the data in the chart, e.g.:
$.get('/path/to/data', function(data) {
g.updateOptions({file: data});
});
See the dynamic update demo for inspiration.
Upvotes: 1