GroupedBar.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. Ext.require('Ext.chart.*');
  2. Ext.require(['Ext.Window', 'Ext.fx.target.Sprite', 'Ext.layout.container.Fit', 'Ext.window.MessageBox']);
  3. Ext.onReady(function () {
  4. var chart = Ext.create('Ext.chart.Chart', {
  5. id: 'chartCmp',
  6. xtype: 'chart',
  7. style: 'background:#fff',
  8. animate: true,
  9. shadow: true,
  10. store: store1,
  11. legend: {
  12. position: 'right'
  13. },
  14. axes: [{
  15. type: 'Numeric',
  16. position: 'bottom',
  17. fields: ['data1', 'data2', 'data3'],
  18. minimum: 0,
  19. label: {
  20. renderer: Ext.util.Format.numberRenderer('0,0')
  21. },
  22. grid: true,
  23. title: 'Number of Hits'
  24. }, {
  25. type: 'Category',
  26. position: 'left',
  27. fields: ['name'],
  28. title: 'Month of the Year'
  29. }],
  30. series: [{
  31. type: 'bar',
  32. axis: 'bottom',
  33. xField: 'name',
  34. yField: ['data1', 'data2', 'data3']
  35. }]
  36. });
  37. var win = Ext.create('Ext.Window', {
  38. width: 800,
  39. height: 600,
  40. minHeight: 400,
  41. minWidth: 550,
  42. hidden: false,
  43. maximizable: true,
  44. title: 'Grouped Bar Chart',
  45. renderTo: Ext.getBody(),
  46. layout: 'fit',
  47. tbar: [{
  48. text: 'Save Chart',
  49. handler: function() {
  50. Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  51. if(choice == 'yes'){
  52. chart.save({
  53. type: 'image/png'
  54. });
  55. }
  56. });
  57. }
  58. }, {
  59. text: 'Reload Data',
  60. handler: function() {
  61. store1.loadData(generateData());
  62. }
  63. }, {
  64. enableToggle: true,
  65. pressed: true,
  66. text: 'Animate',
  67. toggleHandler: function(btn, pressed) {
  68. var chart = Ext.getCmp('chartCmp');
  69. chart.animate = pressed ? { easing: 'ease', duration: 500 } : false;
  70. }
  71. }],
  72. items: chart
  73. });
  74. });