Title: Load PHP-JSON data not working
Last modified: August 30, 2016

---

# Load PHP-JSON data not working

 *  Resolved [Aleharu](https://wordpress.org/support/users/aleharu/)
 * (@aleharu)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/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/](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](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.css
       ```
   
 * This 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?
 * [https://wordpress.org/plugins/amcharts-charts-and-maps/](https://wordpress.org/plugins/amcharts-charts-and-maps/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [martynasma](https://wordpress.org/support/users/martynasma/)
 * (@martynasma)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/load-php-json-data-not-working/#post-6723862)
 * Is perhaps your data PHP file located on different domain than the website displaying
   the chart?
 * Another thing to note is that you have specified the chart to parse dates in 
   the data (`chart.categoryAxis.parseDates = true;`) however “category” fields 
   just hold numeric values (“0”, “1”, etc.)
 * Try removing the above line and see if that helps.
 *  Thread Starter [Aleharu](https://wordpress.org/support/users/aleharu/)
 * (@aleharu)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/load-php-json-data-not-working/#post-6723926)
 * They’re in the same domain but the PHP file is not “inside” WordPress.
 * I removed the line, but still doesn’t work
 *  Thread Starter [Aleharu](https://wordpress.org/support/users/aleharu/)
 * (@aleharu)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/load-php-json-data-not-working/#post-6723929)
 * I can’t use a path using the ‘www…’ so I just change it for ‘../../info.php’
 * Thank you!
 *  Plugin Author [martynasma](https://wordpress.org/support/users/martynasma/)
 * (@martynasma)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/load-php-json-data-not-working/#post-6723999)
 * I’m sorry for not getting back earlier. This somehow slipped through the cracks.
 * Would it be possible to see your setup online where I can check?
 * If you want to keep it private, you can email us directly at [contact@amcahrts.com](https://wordpress.org/support/topic/load-php-json-data-not-working/contact@amcahrts.com?output_format=md).
 * Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Load PHP-JSON data not working’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/amcharts-charts-and-maps_6f74b0.svg)
 * [amCharts: Charts and Maps](https://wordpress.org/plugins/amcharts-charts-and-maps/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amcharts-charts-and-maps/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amcharts-charts-and-maps/)
 * [Active Topics](https://wordpress.org/support/plugin/amcharts-charts-and-maps/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amcharts-charts-and-maps/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amcharts-charts-and-maps/reviews/)

## Tags

 * [json](https://wordpress.org/support/topic-tag/json/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 4 replies
 * 2 participants
 * Last reply from: [martynasma](https://wordpress.org/support/users/martynasma/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/load-php-json-data-not-working/#post-6723999)
 * Status: resolved