Array in JavaScript does not work on pie chart highcharts

1
var conteudodoGrafico = new Array();//cris gráfico
                for(x in data['linha']) {

                     conteudodoGrafico.push('["'+data['linha'][x].nome+'", '+   data['linha'][x].enviado+']'); //cris grafico
}


conteudodoGrafico = ("[ " +conteudodoGrafico+ " ]");
var data_str = JSON.stringify(conteudodoGrafico);

    $('#graficoPizza').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false
        },
        title: {
            text: 'Gráfico SMS'
        },
        subtitle: {
                text: 'Relatório'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                }
            }
        },
       series: [{
                type: 'pie',
                name: 'Quantidade enviados',
                data: JSON.parse(data_str)
              }]
    });
alert(JSON.parse(data_str));

no alert JSON.parse(data_str) of browser is printing like this:

[
    ["AIRPLAN", 2476],
    ["IMPACTO INFORMATICA E TECNOLOGIA", 0],
    ["LINCE ENTREGAS RAPIDAS", 0],
    ["AFRANIO FERREIRA FÉLIX", 1],
    ["FRISSON COMUNICAÇAO E MARKETING LTDA", 0],
    ["GEDALYAS MENEZES DOS SANTOS", 0]
]

    
asked by anonymous 15.05.2014 / 18:14

2 answers

1

// I could solve this: var contentGrafico = new Array ()   for (x in data ['line']) {      [+] [x] .nome + '",' + data ['line'] [x]. sent + ']');   }

Graphical content2 = ("[" + "Graphical content +"] ");

var chart;
        $(document).ready(function() {
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'graficoPizza',
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false
                },
                title: {
                    text: 'Gráfico SMS'
                },
                subtitle: {
                    text: 'Relatório de porcentagem de Enviados'
                },
                 tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: false
                        },
                        showInLegend: true
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 100,
                    borderWidth: 1
                },
                series: [{
                    type: 'pie',
                    name: 'Quantidade enviados',
                    data: JSON.parse(conteudodoGrafico2)
                }]
            });
        });
    
16.05.2014 / 22:37
0

Since you are using jQuery to generate the graph, use it also to do the parse of json.

your series will look like this:

series: [{
    type: 'pie',
    name: 'Quantidade enviados',
    data: jQuery.parseJSON(data_str)
}]

By what oq I was able to play your date was still getting a string instead of an array as you can check in the error in the

jsfiddle

    
15.05.2014 / 20:32