Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / examples / charts / StackedBar.js
1 Ext.require('Ext.chart.*');
2 Ext.require('Ext.layout.container.Fit');
3
4 Ext.onReady(function () {
5     var store = Ext.create('Ext.data.JsonStore', {
6         fields: ['year', 'comedy', 'action', 'drama', 'thriller'],
7         data: [
8                 {year: 2005, comedy: 34000000, action: 23890000, drama: 18450000, thriller: 20060000},
9                 {year: 2006, comedy: 56703000, action: 38900000, drama: 12650000, thriller: 21000000},
10                 {year: 2007, comedy: 42100000, action: 50410000, drama: 25780000, thriller: 23040000},
11                 {year: 2008, comedy: 38910000, action: 56070000, drama: 24810000, thriller: 26940000}
12               ]
13     });
14
15     var panel1 = Ext.create('widget.panel', {
16         width: 800,
17         height: 400,
18         title: 'Stacked Bar Chart - Movies by Genre',
19         renderTo: Ext.getBody(),
20         layout: 'fit',
21         items: {
22             xtype: 'chart',
23             animate: true,
24             shadow: true,
25             store: store,
26             legend: {
27                 position: 'right'
28             },
29             axes: [{
30                 type: 'Numeric',
31                 position: 'bottom',
32                 fields: ['comedy', 'action', 'drama', 'thriller'],
33                 title: false,
34                 grid: true,
35                 label: {
36                     renderer: function(v) {
37                         return String(v).replace(/000000$/, 'M');
38                     }
39                 },
40                 roundToDecimal: false
41             }, {
42                 type: 'Category',
43                 position: 'left',
44                 fields: ['year'],
45                 title: false
46             }],
47             series: [{
48                 type: 'bar',
49                 axis: 'bottom',
50                 gutter: 80,
51                 xField: 'year',
52                 yField: ['comedy', 'action', 'drama', 'thriller'],
53                 stacked: true,
54                 tips: {
55                     trackMouse: true,
56                     width: 65,
57                     height: 28,
58                     renderer: function(storeItem, item) {
59                         this.setTitle(String(item.value[1] / 1000000) + 'M');
60                     }
61                 }
62             }]
63         }
64     });
65 });