• Resolved Aleharu

    (@aleharu)


    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.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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author martynasma

    (@martynasma)

    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

    (@aleharu)

    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

    (@aleharu)

    I can’t use a path using the ‘www…’ so I just change it for ‘../../info.php’

    Thank you!

    Plugin Author martynasma

    (@martynasma)

    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.

    Thanks!

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

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