我想根據json響應動態生成Y
軸。例如:在Extjs 4中動態生成軸和系列
{
"totalCount":"4",
"data":[
{"asOfDate":"12-JAN-14","eventA":"575","eventB":"16","eventC":"13",...},
{"asOfDate":"13-JAN-14","eventA":"234","eventB":"46","eventC":"23",...},
...and many more.
]
}
我想要生成折線圖date vs event
。日期位於x軸上,eventA,eventB,...等應位於Y軸上。到目前爲止,我試過這個:
var fieldsForChart = ['eventA','eventB',...]; //This is hard coded.
Ext.define("TestBug.view.TrendsChart", {
extend: "Ext.chart.Chart",
alias: "widget.trendschart",
store: "Trends",
style: 'background:#fff',
animate: true,
shadow: true,
theme: 'Category1',
legend: {position: 'right'},
axes: [
{
type: "numeric",
position: "left",
fields: [fieldsForChart],
title:"Start Open",
},
{
type: "Time",
dateFormat:"d-M-y",
position: "bottom",
fields: "asOfDate",
title: 'Date'
}
],
series: [
{
type: "line",
axis: "left",
xField: "asOfDate",
yField: "fieldsForChart "
}
]
});
我仍然無法繪製圖表。我想基於json響應動態地渲染軸和系列。希望你能幫助。提前致謝。 :)
這裏是我的模型:
Ext.define("TestBug.model.Trend", {
extend: "Ext.data.Model",
fields: [
{name:"asOfDate",type:"date",dateFormat:"d-M-y"},
{name:"eventA",type:"int"},
{name:"eventB",type:"int"},
...and so on.
]
});
這裏事件的所有東西都是硬編碼的,但我要動態地生成它。
你能顯示整個代碼圖表和商店?我看到的第一個問題是你的數據有字段''日期''而你的圖表使用字段''asOfDate'' – forgivenson
@forgivenson我從json文件讀取和模型類發佈的問題。 –