Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / charts / PieRenderer.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.require('Ext.chart.*');
16 Ext.require(['Ext.Window', 'Ext.fx.target.Sprite', 'Ext.layout.container.Fit']);
17
18 Ext.onReady(function () {
19     store1.loadData(generateData(5, 20));
20
21     var win = Ext.create('Ext.Window', {
22         width: 800,
23         height: 600,
24         minHeight: 400,
25         minWidth: 550,
26         hidden: false,
27         maximizable: true,
28         title: 'Pie Renderer Chart',
29         renderTo: Ext.getBody(),
30         layout: 'fit',
31         tbar: [{
32             text: 'Reload Data',
33             handler: function() {
34                 store1.loadData(generateData(5));
35             }
36         }],
37         items: {
38             id: 'chartCmp',
39             xtype: 'chart',
40             style: 'background:#fff',
41             animate: true,
42             shadow: true,
43             store: store1,
44             series: [{
45                 type: 'pie',
46                 animate: true,
47                 angleField: 'data1', //bind angle span to visits
48                 lengthField: 'data2', //bind pie slice length to views
49                 highlight: {
50                   segment: {
51                     margin: 20
52                   }
53                 },
54                 label: {
55                     field: 'name',   //bind label text to name
56                     display: 'rotate', //rotate labels (also middle, out).
57                     font: '14px Arial',
58                     contrast: true
59                 },                                
60                 style: {
61                     'stroke-width': 1,
62                     'stroke': '#fff'
63                 },
64                 //add renderer
65                 renderer: function(sprite, record, attr, index, store) {
66                     var value = (record.get('data1') >> 0) % 9;
67                     var color = [ "#94ae0a", "#115fa6","#a61120", "#ff8809", "#ffd13e", "#a61187", "#24ad9a", "#7c7474", "#a66111"][value];
68                     return Ext.apply(attr, {
69                         fill: color
70                     });
71                 }
72             }]
73         }
74     });
75 });
76