I'm trying to add Highstock chart in my plugin. It requires input data in json format. But I have some troubles with default json parser in jQuery. I've already read this article, but still can't understand how can I add the chart in the plugin.
Can someone describe how does getJSON() works in wp plugins, and if it's possible to send data from php-function inside the plugin to the jQuery script inside this plugin in json format?
Here is example of highstock script, that I want to place in my plugin:
$(function() {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
// Create the chart
window.chart = new Highcharts.StockChart({
chart : {
renderTo : 'container'
},
rangeSelector : {
selected : 1
},
title : {
text : 'AAPL Stock Price'
},
series : [{
name : 'AAPL',
data : data,
tooltip: {
valueDecimals: 2
}
}]
});
});
});
And php code, that I want to put in function inside the plugin:
global $wpdb;
$table=$wpdb->prefix."table_name";
$query=$wpdb->get_results("SELECT `date`,`value` FROM `".$table."` WHERE `date` BETWEEN '2011' AND '2012' ORDER BY `date` ASC; ", ARRAY_A);
$i=0;
for($j=0; $j<sizeof($query); $j++) {
$result[$j][]=strtotime($query[$j]['date'])*1000;
$result[$j][]=(float)$query[$j]['value'];
}
echo json_encode($result);
Can anyone help? I'm really get tired to seek the solution.