Highcharts JS Uncaught TypeError:x [(中间值)(中间值)(中间值)]不是构造函数

时间:2016-06-16 11:23:04

标签: javascript jquery ajax highcharts

我正在建立一个条形图,从ajax响应中检索选项。但是当我将对象传递给highcharts构造函数时,我得到以下错误

Uncaught TypeError: x[(intermediate value)(intermediate value)(intermediate value)] is not a constructor

我的ajax响应是这样的(用JsonLint验证):

{
    "chart": {
        "type": "column"
    },
    "title": {
        "text": "Resumo diario de Movimentos"
    },
    "subtitle": {
        "text": "Selecione os Fornecedores em questão"
    },
    "xAxis": {
        "categories": [
            "Indiferenciado", "Papel / Cartão", "Madeira", "Vidro", "Metais", "Ramagem", "Pneus", "Plástico Não Reciclável", "Embalão", "REEE", "Lâmpadas", "Pilhas", "Compostagem", "Diversos Incineração", "Diversos Aterro", "Outros", "Diversos", "Embalão/Vidro", "Roupas e Brinquedos", "Cemitério", "Papel", "Cartão", "Papel Porta a Porta", "Orgânico", "RX", "Orgânico Porta a Porta", "Embalão Porta a Porta", "Vidro Porta a Porta", "Plástico Filme", "Esferovite", "Mad. Shopping", "Forum Madeira", "Mad. Carlton", "Capa 2", "Oleos Alimentares Usados", "Papel Saco Azul", "Estilha", "Baterias", "Paletes"
        ],
        "crosshair": true
    },
    "yAxis": {
        "min": 0,
        "title": {
            "text": "Peso (Kg)"
        }
    },
    "tooltip": {

        "shared": true,
        "useHTML": true
    },
    "plotOptions": {
        "column": {
            "pointPadding": 0.2,
            "borderWidth": 0
        }
    },
    "series": [{
            "name": "Tokyo",
            "data": [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 71.5, 106.4, 129.2, 144.0, 55],
            "visible": false
        }, {
            "name": "Tokyo",
            "data": [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 71.5, 106.4, 129.2, 144.0, 55],
            "visible": false
        }

    ]
}

现在当我尝试使用传入数据启动高图时

 <script>
     $(function(){
         $.post("/ajax/getResumo/diario")
                 .done(function(dataInc) {
                     $("#chartContainer").highcharts(dataInc);
                 });
     });

    </script>

我收到以下错误

Uncaught TypeError: x[(intermediate value)(intermediate value)(intermediate value)] is not a constructor

但是,如果我将我的ajax的响应直接复制+粘贴到Highcharts构造函数中,它可以正常工作。

知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

$("#chartContainer").highcharts(JSON.parse(dataInc));

必须解析,传入的响应是作为一个strng