/* 线型图
* Ext JS Library 3.3.0
*/
Ext.chart.Chart.CHART_URL = '../../resources/charts.swf';
Ext.onReady(function(){
var store = new Ext.data.JsonStore({
fields:['name', 'visits', 'views'],
data: [
{name:'Jul 07', visits: 245000, views: 3000000},
{name:'Aug 07', visits: 240000, views: 3500000},
{name:'Sep 07', visits: 355000, views: 4000000},
{name:'Oct 07', visits: 375000, views: 4200000},
{name:'Nov 07', visits: 490000, views: 4500000},
{name:'Dec 07', visits: 495000, views: 5800000},
{name:'Jan 08', visits: 520000, views: 6000000},
{name:'Feb 08', visits: 620000, views: 7500000}
]
});
// 简单例子
new Ext.Panel({
title: 'ExtJS.com Visits Trend, 2007/2008 (No styling)',
renderTo: 'container',
width:500,
height:300,
layout:'fit',
items: {
xtype: 'linechart', //线型图
store: store,
xField: 'name',
yField: 'visits',
listeners: {
itemclick: function(o){
var rec = store.getAt(o.index);
Ext.example.msg('Item Selected', 'You chose {0}.', rec.get('name'));
}
}
}
});
// 简单例子(有样式的)
new Ext.Panel({
iconCls:'chart', //在头部工具栏里(headerTool)加上chart图标。
title: 'ExtJS.com Visits Trend, 2007/2008 (Simple styling)',
frame:true,
renderTo: 'container',
width:500,
height:300,
layout:'fit',
items: {
xtype: 'linechart',
store: store,
url: '../../resources/charts.swf',
xField: 'name',
yField: 'visits',
yAxis: new Ext.chart.NumericAxis({ //对y轴显示进行设置。
displayName: 'Visits',
labelRenderer : Ext.util.Format.numberRenderer('0,0')
}),
tipRenderer : function(chart, record){
return Ext.util.Format.number(record.data.visits, '0,0') + ' visits in ' + record.data.name;
}
}
});
// 复杂例子(23_todo)
new Ext.Panel({
iconCls:'chart',
title: 'ExtJS.com Visits and Pageviews, 2007/2008 (Full styling)',
frame:true,
renderTo: 'container',
width:500,
height:300,
layout:'fit',
items: {
xtype: 'columnchart', //柱形图
store: store,
url:'../../resources/charts.swf',
xField: 'name',
yAxis: new Ext.chart.NumericAxis({
displayName: 'Visits',
labelRenderer : Ext.util.Format.numberRenderer('0,0')
}),
tipRenderer : function(chart, record, index, series){
if(series.yField == 'visits'){
return Ext.util.Format.number(record.data.visits, '0,0') + ' visits in ' + record.data.name;
}else{
return Ext.util.Format.number(record.data.views, '0,0') + ' page views in ' + record.data.name;
}
},
chartStyle: {
padding: 10,
animationEnabled: true,
font: {
name: 'Tahoma',
color: 0x444444,
size: 11
},
dataTip: {
padding: 5,
border: {
color: 0x99bbe8,
size:1
},
background: {
color: 0xDAE7F6,
alpha: .9 // 透明度
},
font: {
name: 'Tahoma',
color: 0x15428B,
size: 10,
bold: true
}
},
xAxis: {
color: 0x69aBc8,
majorTicks: {color: 0x69aBc8, length: 4},
minorTicks: {color: 0x69aBc8, length: 2},
majorGridLines: {size: 1, color: 0xeeeeee}
},
yAxis: {
color: 0x69aBc8,
majorTicks: {color: 0x69aBc8, length: 4},
minorTicks: {color: 0x69aBc8, length: 2},
majorGridLines: {size: 1, color: 0xdfe8f6}
}
},
series: [{
type: 'column',
displayName: 'Page Views',
yField: 'views',
style: {
image:'bar.gif',
mode: 'stretch',
color:0x99BBE8
}
},{
type:'line',
displayName: 'Visits',
yField: 'visits',
style: {
color: 0x15428B
}
}]
}
});
});
/* 饼图
* Ext JS Library 3.3.0
*/
Ext.chart.Chart.CHART_URL = '../../resources/charts.swf';
Ext.onReady(function(){
var store = new Ext.data.JsonStore({
fields: ['season', 'total'],
data: [{
season: 'Summer',
total: 150
},{
season: 'Fall',
total: 245
},{
season: 'Winter',
total: 117
},{
season: 'Spring',
total: 184
}]
});
new Ext.Panel({
width: 400,
height: 400,
title: 'Pie Chart with Legend(图例) - Favorite Season',
renderTo: 'container',
items: {
xtype: 'piechart', // 饼图
store: store,
dataField: 'total',
categoryField: 'season',
//extra styles get applied to the chart defaults(往默认样式添加额外样式)
extraStyle:
{
legend:
{
display: 'bottom',
padding: 5,
font:
{
family: 'Tahoma',
size: 13
}
}
}
}
});
});
/* 条形图
* Ext JS Library 3.3.0
*/
Ext.chart.Chart.CHART_URL = '../../resources/charts.swf';
Ext.onReady(function(){
var store = new Ext.data.JsonStore({// comedy_喜剧;action_动作;drama_戏剧;thriller_惊悚片;
fields: ['year', 'comedy', 'action', 'drama', 'thriller'],
data: [
{year: 2005, comedy: 34000000, action: 23890000, drama: 18450000, thriller: 20060000},
{year: 2006, comedy: 56703000, action: 38900000, drama: 12650000, thriller: 21000000},
{year: 2007, comedy: 42100000, action: 50410000, drama: 25780000, thriller: 23040000},
{year: 2008, comedy: 38910000, action: 56070000, drama: 24810000, thriller: 26940000}
]
});
new Ext.Panel({
width: 600,
height: 400,
renderTo: 'container',
title: 'Stacked Bar Chart - Movie Takings by Genre(风格)',
items: {
xtype: 'stackedbarchart', // 条形图
store: store,
yField: 'year',
xAxis: new Ext.chart.NumericAxis({
stackingEnabled: true,
labelRenderer: Ext.util.Format.usMoney
}),
series: [{
xField: 'comedy',
displayName: 'Comedy'
},{
xField: 'action',
displayName: 'Action'
},{
xField: 'drama',
displayName: 'Drama'
},{
xField: 'thriller',
displayName: 'Thriller'
}]
}
});
});
/*!
* Ext JS Library 3.3.0
*/
function generateData(){ //产生数据函数:
var data = [];
for(var i = 0; i < 12; ++i){
data.push([Date.monthNames[i], (Math.floor(Math.random() * 11) + 1) * 100]);
}
return data;
}
Ext.onReady(function(){
var store = new Ext.data.ArrayStore({
fields: ['month', 'hits'],
data: generateData()
});
new Ext.Panel({
width: 700,
height: 400,
renderTo: document.body,
title: 'Column Chart with Reload - Hits per Month',
tbar: [{
text: 'Load new data set',
handler: function(){
store.loadData(generateData());
}
}],
items: {
xtype: 'columnchart', // 柱形图
store: store,
yField: 'hits',
url: '../../resources/charts.swf',
xField: 'month',
xAxis: new Ext.chart.CategoryAxis({
title: 'Month'
}),
yAxis: new Ext.chart.NumericAxis({
title: 'Hits'
}),
extraStyle: {
xAxis: {
labelRotation: -90 //旋转
}
}
}
});
});