Skip to content Skip to sidebar Skip to footer

Passing Data From $ajax Call To Highcharts

I have an ajax call $(function () { $.ajax({ url: '../../getdaily.php', type:'POST', dataType: '', success: function(output_string){

Solution 1:

Just wrap your highcharts in a function, pass the ajax response as the function's argument and load the data (in argument) to your high charts, as:

function my_chart(response) {
    $('#container').highcharts({
        ...
        ...
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: response
        }]
    });
}

and call your function in ajax response, as:

    $(function () {
        $.ajax({
            url: '../../getdaily.php',
            type:'POST',
            dataType: '',
            success: function(output_string){
               //call my_chart function
               var parsed_response = jQuery.parseJSON(output_string);
               my_chart(parsed_response);
            },
            error: function (xhr, ajaxOptions, thrownError){
                console.log(xhr.statusText);
                console.log(thrownError);
            }
    });
});

Post a Comment for "Passing Data From $ajax Call To Highcharts"