Column.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. Ext.require('Ext.chart.*');
  2. Ext.require(['Ext.Window', 'Ext.layout.container.Fit', 'Ext.fx.target.Sprite', '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. axes: [{
  12. type: 'Numeric',
  13. position: 'left',
  14. fields: ['data1'],
  15. label: {
  16. renderer: Ext.util.Format.numberRenderer('0,0')
  17. },
  18. title: 'Number of Hits',
  19. grid: true,
  20. minimum: 0
  21. }, {
  22. type: 'Category',
  23. position: 'bottom',
  24. fields: ['name'],
  25. title: 'Month of the Year'
  26. }],
  27. series: [{
  28. type: 'column',
  29. axis: 'left',
  30. highlight: true,
  31. tips: {
  32. trackMouse: true,
  33. width: 140,
  34. height: 28,
  35. renderer: function(storeItem, item) {
  36. this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data1') + ' $');
  37. }
  38. },
  39. label: {
  40. display: 'insideEnd',
  41. 'text-anchor': 'middle',
  42. field: 'data1',
  43. renderer: Ext.util.Format.numberRenderer('0'),
  44. orientation: 'vertical',
  45. color: '#333'
  46. },
  47. xField: 'name',
  48. yField: 'data1'
  49. }]
  50. });
  51. var win = Ext.create('Ext.Window', {
  52. width: 800,
  53. height: 600,
  54. minHeight: 400,
  55. minWidth: 550,
  56. hidden: false,
  57. maximizable: true,
  58. title: 'Column Chart',
  59. renderTo: Ext.getBody(),
  60. layout: 'fit',
  61. tbar: [{
  62. text: 'Save Chart',
  63. handler: function() {
  64. Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  65. if(choice == 'yes'){
  66. chart.save({
  67. type: 'image/png'
  68. });
  69. }
  70. });
  71. }
  72. }, {
  73. text: 'Reload Data',
  74. handler: function() {
  75. store1.loadData(generateData());
  76. }
  77. }],
  78. items: chart
  79. });
  80. });