Load PHP-JSON data not working
-
I’m following this tutorial: http://www.amcharts.com/tutorials/using-php-to-hook-up-charts-to-mysql-data-base/ in WordPress
My PHP file (http://www.myweb.com/info.php) is returning:
[ { "category": "0", "value1": 4386888.60026, "value2": 2279 }, { "category": "1", "value1": 3702907.01667, "value2": 60 }, { "category": "2", "value1": 1277778.24804, "value2": 383 }, { "category": "3", "value1": 1796774.7877, "value2": 2944 }, { "category": "4", "value1": 3522402.95305, "value2": 4111 }, { "category": "5", "value1": 2795358.12613, "value2": 6501 }, { "category": "6", "value1": 3309690.86785, "value2": 7499 } ]I have the following resources:
http://www.amcharts.com/lib/3/amcharts.js http://www.amcharts.com/lib/3/serial.js http://www.amcharts.com/lib/3/style.cssThis HTML:
<div id="%CHART%" style="width: 600px; height: 300px;"></div>And JavaScript:
AmCharts.loadJSON = function(url) { // create the request if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari var request = new XMLHttpRequest(); } else { // code for IE6, IE5 var request = new ActiveXObject('Microsoft.XMLHTTP'); } // load it // the last "false" parameter ensures that our code will wait before the // data is loaded request.open('GET', url, false); request.send(); // parse adn return the output return eval(request.responseText); }; AmCharts.ready(function() { // load the data var chartData = AmCharts.loadJSON('http://www.myweb.com/info.php'); // this is a temporary line to verify if the data is loaded and parsed correctly // please note, that console.debug will work on Safari/Chrome only console.debug(chartData); // build the chart // ... }); var %CHART%; // create chart AmCharts.ready(function() { // load the data var chartData = AmCharts.loadJSON('http://www.myweb.com/info.php'); // SERIAL CHART chart = new AmCharts.AmSerialChart(); chart.pathToImages = "http://www.amcharts.com/lib/images/"; chart.dataProvider = chartData; chart.categoryField = "category"; chart.dataDateFormat = "YYYY-MM-DD"; // GRAPHS var graph1 = new AmCharts.AmGraph(); graph1.valueField = "value1"; graph1.bullet = "round"; graph1.bulletBorderColor = "#FFFFFF"; graph1.bulletBorderThickness = 2; graph1.lineThickness = 2; graph1.lineAlpha = 0.5; chart.addGraph(graph1); var graph2 = new AmCharts.AmGraph(); graph2.valueField = "value2"; graph2.bullet = "round"; graph2.bulletBorderColor = "#FFFFFF"; graph2.bulletBorderThickness = 2; graph2.lineThickness = 2; graph2.lineAlpha = 0.5; chart.addGraph(graph2); // CATEGORY AXIS chart.categoryAxis.parseDates = true; // WRITE chart.write("%CHART%"); });But still doesn’t work, how could it be?
The topic ‘Load PHP-JSON data not working’ is closed to new replies.