Highcharts Error: Uncaught TypeError: Can not read property 'setData' of undefined

1

I seem to miss the chart

$(document).ready(function(){

      $('#grafico1').highcharts({
            chart: {
                zoomType: 'x',reflow: true,resetZoomButton: {position: {align: 'left',x: 0}},
                type: 'column',
                events: {
                        load: function(event){
                            var chart = this;
                            var urlCuentasGrupos = "";

                            urlCuentasGrupos = "/_api/Web/Lists/GetByTitle('Cuentas')/Items?&$select=Grupos,Grupos/Id&$top=5000"                        
                            var cuentas_grupos = [];


                            $.ajax({
                                url: urlCuentasGrupos,
                                async: false,
                                method: "GET",
                                headers: { "Accept": "application/json; odata=verbose" },
                                success: function(data){

                                    $.each(data.d.results, function(index, fila){                   

                                        if($.inArray(fila.Grupos,cuentas_grupos) == -1){
                                            cuentas_grupos.push(fila.Grupos);

                                        }                       

                                    });

                                    $.each(cuentas_grupos, function(index, nombre_grupo){   

                                        var urlFiltroCostosProyectados = "";
                                        urlFiltroCostosProyectados = "/_api/Web/Lists/GetByTitle('Costos')/Items?$select=*,Cuenta/Grupos&$expand=Cuenta/Grupos&$filter=Cuenta/Grupos eq '"+nombre_grupo+"'";

                                        var suma = 0;
                                        //SUMA
                                        $.ajax({
                                            url : urlFiltroCostosProyectados,
                                            async: false,
                                            method: "GET",
                                            headers: { "Accept": "application/json; odata=verbose" },
                                            success: function(data){ 

                                                $.each(data.d.results, function(index, obj){

                                                        suma = suma + parseInt(obj.Monto);                                                                                      

                                                });
                                                console.log(nombre_grupo + " " + suma);
                                                chart.series[index].setData(suma);

                                            }
                                        });

                                    });

                                    chart.xAxis[0].setCategories(cuentas_grupos);
                                }       
                            });

                        }   
                    },
                },
                title: {
                    text: 'Costos',
                    align: 'left',
                    x: 45,
                style: {
                    "color": "#706f6f",
                    "fontSize": "25px"
                }
            },
            xAxis: {
                categories: [""]
            },
            yAxis: {
                min: 0,
                title: {
                    text: ''
                },
                labels: {
                    formatter: function(){
                        return this.value;
                    }
                },
            },
            plotOptions: {
                line: {
                    dataLabels: {
                        enabled: true
                    },
                    enableMouseTracking: false
                }
            },
            colors: [
                '#b5b5b5',
                '#e01d1d',
            ],
            credits: {
                enabled: false
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle'
            },
            series: [{
                name: 'Real 2',
                data: ''
            }, {
                name: 'Proyectado 2',
                data: '' 
            }]
        });     
    });
    
asked by Diego Sagredo 07.02.2017 в 15:11
source

0 answers