【发布时间】:2011-01-15 03:18:27
【问题描述】:
大家好!首先,我知道这种东西很糟糕,但这就是我想象实现目标的方式。
这里是交易:我有一个包含数组的 JSon 对象,但不幸的是,我必须遍历一个 JSon 对象的列表,然后遍历我之前提到的那个数组。 JSon 对象如下(是葡萄牙语,不过你们可以看懂):
{"produtos":[{"Key":"DERIVADOS DE FERRO","Value":217816909},{"Key":"MADEIRAS, SUAS MANUFATURAS E MOBILIÁRIO MÉDICO CIRÚRGICO","Value":117812290},{"Key":"CELULOSE, 帕佩尔·苏阿斯 OBRAS","Value":100086937},{"Key":"CARNE SUÍNA","Value":81738783},{"Key":"CARNE BOVINA","Value":74894768},{"Key":"CARNE DE AVES","Value":65292433},{"Key":"Outros","Value":444520811}],"ano":2005,"tipo":1}
Produtos 是我提到的数组,还有另外两个重要的值:ano(年份)和 tipo(类型)。我的代码如下:
jQuery.getJSON("/webportos/Porto/GraficoComercio?id=" + iddoporto.className + "&ano=2005", null, function (items) {
jQuery.each(items, function (itemNo, item) {
jQuery.each(item.produtos, function (dicNo, dic) {
options.series.push({ name: dic.Key, data: dic.Value});
options.title.text = "Comércio - "+item.ano;
options.yAxis.title.text = "Exportação";
options.tooltip.formatter = function () {
return '<b><u>' + this.series.name + '</u></b><br/><b>' + this.x + '</b>: ' + this.y + ' ';
}
});
});
chart = new Highcharts.Chart(options);
});
这段代码让 Chrome javascript 控制台显示:
ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js:32 Uncaught TypeError: Cannot read property 'length' of undefined
你们能帮帮我吗?
【问题讨论】:
标签: javascript highcharts