Advertisement
prasadshir

ExtJS Chart Example

May 8th, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type='text/javascript'>
  2. Ext.require('Ext.chart.*');
  3. Ext.require('Ext.data.*');
  4. Ext.require(['Ext.Window', 'Ext.layout.container.Fit', 'Ext.fx.target.Sprite', 'Ext.window.MessageBox']);
  5.  
  6. Ext.onReady(function () {
  7.  
  8. var store1 = Ext.create('Ext.data.JsonStore', {
  9.         fields: ['region', 'amount'],
  10.         data: [
  11.         {"region":"West Zone","amount":4905060},
  12.         {"region":"East Zone","amount":2310456},
  13.         {"region":"South Zone - I","amount":9729035},
  14.         {"region":"North Zone","amount":2574571},
  15.         {"region":"International","amount":558107},
  16.         {"region":"South Zone - II","amount":1197225},
  17.         {"region":"West Zone - Pharma","amount":7188400},
  18.         {"region":"South Zone I - Pharma","amount":985000},
  19.         {"region":"North Zone - Pharma","amount":324000}],
  20.     autoLoad:true
  21.  
  22. });
  23.     var donut = false,
  24.         chart = Ext.create('Ext.chart.Chart', {
  25.             xtype: 'chart',
  26.             animate: true,
  27.             store: store1,
  28.             shadow: true,
  29.             legend: {
  30.                 position: 'right'
  31.             },
  32.             insetPadding: 60,
  33.             theme: 'Base:gradients',
  34.             series: [{
  35.                 type: 'pie',
  36.                 field: 'amount',
  37.                 showInLegend: true,
  38.                 donut: donut,
  39.                 tips: {
  40.                   trackMouse: true,
  41.                   width: 140,
  42.                   height: 28,
  43.                   renderer: function(storeItem, item) {
  44.                     //calculate percentage.
  45.                     var total = 0;
  46.                     store1.each(function(rec) {
  47.                         total += rec.get('amount');
  48.                     });
  49.                     this.setTitle(storeItem.get('region') + ': ' + Math.round(storeItem.get('amount') / total * 100) + '%');
  50.                   }
  51.                 },
  52.                 highlight: {
  53.                   segment: {
  54.                     margin: 20
  55.                   }
  56.                 },
  57.                 label: {
  58.                     field: 'region',
  59.                     display: 'rotate',
  60.                     contrast: true,
  61.                     font: '18px Arial'
  62.                 }
  63.             }]
  64.         });
  65.  
  66.     var panel1 = Ext.create('widget.panel', {
  67.         width: 800,
  68.         height: 600,
  69.         title: 'Sales Report',
  70.         renderTo: Ext.getBody(),
  71.         layout: 'fit',
  72.         tbar: [{
  73.             text: 'Save Chart',
  74.             handler: function() {
  75.                 Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  76.                     if(choice == 'yes'){
  77.                         chart.save({
  78.                             type: 'image/png'
  79.                         });
  80.                     }
  81.                 });
  82.             }
  83.         }, {
  84.             enableToggle: true,
  85.             pressed: false,
  86.             text: 'Donut',
  87.             toggleHandler: function(btn, pressed) {
  88.                 chart.series.first().donut = pressed ? 35 : false;
  89.                 chart.refresh();
  90.             }
  91.         }],
  92.         items: chart
  93.     });
  94. });
  95.  
  96.  
  97.  
  98. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement