Highcharts jQuery.getJSON

Asked

Viewed 256 times

1

I want to build a chart using Highcharts, where I get Json, but when creating the chart, for example: "column", the bars are not displayed.

I make a loop, because the data is received from a table with several columns. Follow the code for better understanding:

$(document).ready(function() {
        var options = {
            chart: {
                renderTo: 'container',
                type: 'line',
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: 'test',
                x: -20 //center
            },
            subtitle: {
                text: '',
                x: -20
            },
            xAxis: {
                categories: [],
                crosshair: true
            },
            yAxis: {
                title: {
                    text: 'test'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                formatter: function() {
                        return '<b>'+ this.series.name +'</b><br/>'+
                        this.x +': '+ this.y;
                }
            },
            plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'top',
                x: -10,
                y: 100,
                borderWidth: 0
            },
            series: []
        }

        $.getJSON("caminhoDaUrl", function(json) {
            for( var i in json ){
                var u = json[i];
                options.xAxis.categories = json[i]['item'];
                options.series[i] = {};
                options.series[i].name = json[i]['item'];
                options.series[i].data = json[i]['item'];
            }

            chart = new Highcharts.Chart(options);
        });
    });

Thank you for your attention, if anyone can help me!!!

  • 1

    What appears if you do console.log(json); in the first line of that getJSON?

  • It returns [Object, Object, Object, Object, Object] as expected!

  • Can you copy this object and make a jsFiddle with it? so we can help from there, since so far it seems to work well.

  • The code is the same as that! You can help me?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.