当时间作为图表的X轴时, 可以用 TimeAxis 来自定义时间显示的格式, 具体示例:
// 测试 以时间为坐标轴
var timeStore = new Ext.data.JsonStore({
fields: [
{
name: "Date",
mapping: "Date",
type: "date", // 与 convert 一致
//dateFormat: "Y-m" //(与日期数据格式一致)默认当前day -- 只是显示的时候, 错位??
convert: function(value, record){
return new Date(value); //默认day:01
}
},
"Count"
],
data:[
{"Date": "2013-01", "Count": 12},
{"Date": "2013-02", "Count": 44},
{"Date": "2013-03", "Count": 13},
{"Date": "2013-04", "Count": 25}
]
});
// 图表
Ext.create({
xtype: "panel",
renderTo: Ext.getBody(),
width: 400,
height: 300,
items: [
{
xtype: "linechart",
store: timeStore,
xField: "Date",
yField: "Count",
//转换为时间格式
xAxis: new Ext.chart.TimeAxis({
// 定义起止日期 - 静态,
minimum: new Date("2013-01"),
maximum: new Date("2013-04"),
//majorUnit: 2,
//labelRenderer : Ext.util.Format.dateRenderer("m") //只
labelRenderer: function(value){
// var date = new Date(value);
return value.format("y-n");
}
}),
chartStyle: {
xAxis: {
// 显示网格线
majorGridLines: {size: 1, color: 0x0000ff}
}
}
}
]
});