Extjs4图表未绘制正确的数据
我在 Extjs4 中为我的一个项目创建了一个简单的折线图,但该图表未绘制正确的数据。
该图表使用与网格相同的存储,但不显示相同的数据。如果不能完全解决问题,是否有任何方法可以追踪问题的根源?
以下是我用来生成图表的代码。
{
xtype: 'chart',
animate: true,
shadow: true,
store: 'Dataalls',
legend: {
position: 'top'
},
axes: [{
type: 'Numeric',
position: 'left',
title: 'Wind Speed',
fields: ['windspeed'],
grid: true
}, {
type: 'Category',
position: 'bottom',
title: 'Time',
fields: ['time']
}],
series: [{
type: 'line',
axis: 'left',
xField: ['time'],
yField: ['windspeed']
}]
}
(我尝试使用 type: 'Time' 作为 x 轴,但收到错误“date.getFullYear 不是函数”)
I created a simple line chart in Extjs4 for one of my projects, and the chart is not plotting the right data.
The chart uses the same store as the grid, but not showing the same data. Is there any way to trace the source of the problem, if not fixing it altogether?
The following is the code I use to generate the chart.
{
xtype: 'chart',
animate: true,
shadow: true,
store: 'Dataalls',
legend: {
position: 'top'
},
axes: [{
type: 'Numeric',
position: 'left',
title: 'Wind Speed',
fields: ['windspeed'],
grid: true
}, {
type: 'Category',
position: 'bottom',
title: 'Time',
fields: ['time']
}],
series: [{
type: 'line',
axis: 'left',
xField: ['time'],
yField: ['windspeed']
}]
}
(I tried using type: 'Time' for the x axis but gets the error "date.getFullYear is not a function" )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 date.getFullYear() 我怀疑您的日期字符串无法解析为 Date 对象。您能否发布其他支持代码,最好是商店和网格的完整代码?如果您想使用时间轴,您需要通过以下方式将日期字符串转换为日期对象:
});
为了调试图表无法正确显示,我会将图表对象分配给 var 并在该变量分配之后的 Firebug 断点中,以便能够检查图表 js 对象并查看内部数据。
For the date.getFullYear() I suspect your date string is not parsable into a Date object. Could you post your other supporting code, ideally the full code of the Store and Grid? If you'd like to use the Time Axis you'll need to convert your date String into a date object via something along the lines of:
});
For debugging the chart not displaying correctly, I'd place assign your chart object to a var and in Firebug breakpoint after that variable assignment to be able to inspect your chart js object and look at the data inside.
我在使用时间时遇到了类似的问题。只需通过定义我的模型字段类型来修复它:
fields: [{name: 'date', type: 'Date'}, {name: 'close',type:'float'}]
至于为什么你的图表会这样绘制,我之前也得到过,我意识到 json 将其作为字符串传递,所以我也需要定义为浮点数。我在 php 端对此进行了修复,首先将其强制为 float,然后再将其作为 json 传递。
I had a similar problem when using Time. Just fixed it by defining my model field types:
fields: [{name: 'date', type: 'Date'}, {name: 'close',type:'float'}]
As for why your chart is plotting like that, I got that before too, I realised that the json was passing it as a string, so I need to to be defined as a float too. I did a fix for that on the php end, by forcing it as a float first before I passed it over as json.