我正在建立一个条形图,从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构造函数中,则效果很好。
任何想法如何解决这个问题?
最佳答案
$("#chartContainer").highcharts(JSON.parse(dataInc));
必须解析,传入的响应作为字符串来