score:1

Accepted answer

thanks to the statement from sebastian, i reworked my php which generates the json as well as the client side, and it works perfectly. for others having the same issue, here is the correct code:

the json can be verified with jsonlint.

server-side:

$values = array();
$values[] = array(2000,20);
$values[] = array(2001,10);
$values[] = array(2002,12);

$data[] = array("name" => "germany", "data" => $values);    

unset($values);
$values[] = array(2000,8);
$values[] = array(2001,4);
$values[] = array(2002,10);

$data[] = array("name" => "france", "data" => $values); 

header("content-type: application/json"); 

echo $_get['callback']. '('. json_encode($data) . ')';

client-side:

<body>

    <div id="container" style="width: 600px; height: 400px;"></div>

    <script type="text/javascript">

        $(document).ready(function() {
            var options = {
                chart: {
                    renderto: 'container',
                    type: 'spline'
                },
                series: [{}]
            };


            var url =  "http://xxx/jsonp_response.php?callback=?";


            $.getjson(url, {selectedcountries: "germany,france", type: "jsonp"})
                .done(function(data)
                {
                    options.series = data;
                    var chart = new highcharts.chart(options);
                })
                .fail(function(jqxhr, textstatus, error) 
                {
                    var err = textstatus + ", " + error;
                    console.log( "request failed: " + err );
                })
        });

    </script> 

</body>

score:1

in case when your json is validate (containse number values) you dont need to parse it and push values for categories etc. so refer your json to series object and run in chart.


Related Query

More Query from same tag