Arush Kamboj
Arush Kamboj

Reputation: 713

Highcharts: Not rendering on getJSON

I am trying to render a Pie Chart (Semi Circle Donut) with the dynamic data returned by a php file.

data returned by data.php:
echo json_encode($overview)

output: {"Apple":184,"Mango":105,"Oranges":30,"Grapes":17} (This list is dynamic)

Here is what I am doing in the jQuery:

$(document).ready(function(){

$('#show').click(function(){
    var chart;
    var options = {
            chart: {
            renderTo: 'container',
            plotBackgroundColor: null,
            plotBorderWidth: 0,
            plotShadow: false
        },
        title: {
            text: 'Browser<br>shares<br>2015',
            align: 'center',
            verticalAlign: 'middle',
            y: 40
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                dataLabels: {
                    enabled: true,
                    distance: -50,
                    style: {
                        fontWeight: 'bold',
                        color: 'white',
                        textShadow: '0px 1px 2px black'
                    }
                },
                startAngle: -90,
                endAngle: 90,
                center: ['50%', '75%']
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            innerSize: '50%',

        }]
    }; //var options ends here

    $.getJSON("data.php", function(json) {
        json =  JSON.stringify(json);

        options.series[0] = {};

        options.series[0].data = json[0]['json'];
        chart = new Highcharts.Chart(options);
     });

    });
});

I have tried to follow various questions on this but with no luck. Please suggest what am I missing.

Upvotes: 0

Views: 193

Answers (2)

Sebastian Bochan
Sebastian Bochan

Reputation: 37588

Your data should be an array not object. As a result you need to achieve this figure:

["Apple":184,"Mango":105,"Oranges":30,"Grapes":17]

Upvotes: 1

Noman
Noman

Reputation: 4116

You didn't initialize highcharts with options.

$('#container').highcharts(options)

Upvotes: 0

Related Questions