//单个column的情况
var store = Ext.create('Ext.data.JsonStore', {
fields: ['name', 'data'],
data: [
{ 'name': 'metric one', 'data':10 },
{ 'name': 'metric two', 'data': 7 },
{ 'name': 'metric three', 'data': 5 },
{ 'name': 'metric four', 'data': 2 },
{ 'name': 'metric five', 'data':27 }
]
});
Ext.create('Ext.chart.Chart', {
renderTo: Ext.getBody(),
width: 500,
height: 300,
animate: true,
store: store,
legend : {
position : 'bottom'
},
axes: [
{
type: 'Numeric',
position: 'left',
fields: ['data'],
label: {
renderer: Ext.util.Format.numberRenderer('0,0')
},
title: 'Sample Values',
grid: true,
minimum: 0
},
{
type: 'Category',
position: 'bottom',
fields: ['name'],
title: 'Sample Metrics'
}
],
series: [
{
type: 'column',
axis: 'left',
highlight: true,
tips: {
trackMouse: true,
width: 140,
height: 28,
renderer: function(storeItem, item) {
this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data') + ' $');
}
},
label: {
display: 'insideEnd',
'text-anchor': 'middle',
field: 'data',
renderer: Ext.util.Format.numberRenderer('0'),
orientation: 'vertical',
color: '#333'
},
xField: 'name',
yField: 'data',
style : {
fill : 'red'
},
renderer : function(sprite, record, attributes){
return Ext.apply(attributes, {fill:'red'});
}
}
]
});
//多个column的情况
Ext.onReady(function(){
var store = Ext.create('Ext.data.JsonStore', {
fields: ['name', 'data', 'data1'],
data: [
{ 'name': 'metric one', 'data':10 , 'data1':15},
{ 'name': 'metric two', 'data': 7 , 'data1':12},
{ 'name': 'metric three', 'data': 5 , 'data1':10},
{ 'name': 'metric four', 'data': 2 , 'data1':7},
{ 'name': 'metric five', 'data':27 , 'data1':32}
]
});
var colors = ['red', 'blue'];
var chart = Ext.create('Ext.chart.Chart', {
renderTo: Ext.getBody(),
width: 500,
height: 300,
animate: true,
legend : {position:'bottom', colors:colors},
store: store,
axes: [
{
type: 'Numeric',
position: 'left',
fields: ['data', 'data1'],
label: {
renderer: Ext.util.Format.numberRenderer('0,0')
},
title: 'Sample Values',
grid: true,
minimum: 0
},
{
type: 'Category',
position: 'bottom',
fields: ['name'],
title: 'Sample Metrics'
}
],
series: [
{
type: 'column',
axis: 'left',
highlight: true,
tips: {
trackMouse: true,
width: 140,
height: 28,
renderer: function(storeItem, item) {
this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data') + ' $');
}
},
xField: 'name',
yField: ['data', 'data1']
}
]
});
Ext.apply(chart.themeAttrs.colors, colors);
chart.legend.redraw();
chart.redraw();
});