您的位置:首页 > Web前端 > JavaScript

extjs使用store加载远程数据chart报错

2013-01-24 22:46 435 查看
extjs使用store加载远程数据到chart组件时,出现警告信息

在firebug中可见日志输出如下:

Unexpected value NaN parsing height attribute.

Unexpected value NaN parsing y attribute.

此处store数据是来自solr查询结果,chart为pie饼图类型,其它类型图表未做测试。

由于store中的数据是动态从远端服务器获取的,在store提供给chart时,store中的数据一般情况下是空的,这时chart使用空的store就会出现上面的警告信息。

解决的办法就是在store加载数据成功之后才去创建chart,这样就能保证是有数据的store了,自然也不会出现警告了。

以下是部分代码:

// 定义数据模型
Ext.define('MyChart', {
extend : 'Ext.data.Model',
fields : [{
name : 'type',
mapping : 'groupValue'
}, {
name : 'num',
mapping : 'doclist.numFound',
type : 'int'
}]
});


// 定义store

var store = Ext.create('Ext.data.JsonStore', {
model : 'MyChart',
proxy : {
type : 'ajax',
url : 'solr/select/',
reader : {
type : 'json',
root : 'grouped.someField.groups'
},
extraParams : {
'fl' : '*',
'q' : '*:*',
'group' : true,
'group.field' : 'someField',
'group.ngroups' : true,
'wt' : 'json'
}
}
});


// 加载数据,成功后绘制chart

store.load({
callback : function(r, options, success) {
if (success == false) {
// show some error message
} else {
// create chart
}
}
});


转载地址:http://flyash.itcao.com/post_1142.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: