External Data – PHP Charts & Graphs https://phpchart.com Making charts in PHP is simple again. Sat, 01 Jul 2017 02:01:29 +0000 en-US hourly 1 https://wordpress.org/?v=5.8.13 External Data Source through AJAX https://phpchart.com/examples/external-data-source-through-ajax/ https://phpchart.com/examples/external-data-source-through-ajax/#respond Wed, 09 May 2012 05:42:27 +0000 http://phpchart.net/?p=658 Call set_data_renderer() function, and pass the following javascript function as js::ajaxDataRenderer. Note the js:: prefix indicating an external javascript function. Javascript 123456789101112131415var ajaxDataRenderer =     function(url, plot)     {         var ret = null;         $.ajax({             // have to use synchronous […]

The post External Data Source through AJAX appeared first on PHP Charts & Graphs.

]]>
Call set_data_renderer() function, and pass the following javascript function as js::ajaxDataRenderer. Note the js:: prefix indicating an external javascript function.

Javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var ajaxDataRenderer =
    function(url, plot)
    {
        var ret = null;
        $.ajax({
            // have to use synchronous here, else returns before data is fetched
            async: false,
            url: url,
            dataType:'json',
            success: function(data) {
                ret = data;
            }
        });
        return ret;
    };

In phpChart constructor, pass the external data source as the first parameter as either a file or URL. In this example, it points to jsondata.txt which is external text file on the same server. But it also can be a URL to an external site.

PHP

1
2
3
4
5
$data1 = array();
$pc = new C_PhpChartX('./jsondata.txt','basic_chart_ajax');
$pc->set_title(array('text'=>'Basic Chart Ajax'));
$pc->set_data_renderer("js::ajaxDataRenderer");
$pc->draw();

jsondata.txt

1
[[1, 3, 2, 4, 6, 9]]

Live demo

The post External Data Source through AJAX appeared first on PHP Charts & Graphs.

]]>
https://phpchart.com/examples/external-data-source-through-ajax/feed/ 0