Bar.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 textArea;
  5. Ext.chart.theme.White = Ext.extend(Ext.chart.theme.Base, {
  6. constructor: function() {
  7. Ext.chart.theme.White.superclass.constructor.call(this, {
  8. axis: {
  9. stroke: 'rgb(8,69,148)',
  10. 'stroke-width': 1
  11. },
  12. axisLabel: {
  13. fill: 'rgb(8,69,148)',
  14. font: '12px Arial',
  15. 'font-family': '"Arial',
  16. spacing: 2,
  17. padding: 5,
  18. renderer: function(v) { return v; }
  19. },
  20. axisTitle: {
  21. font: 'bold 18px Arial'
  22. }
  23. });
  24. }
  25. });
  26. var chart = Ext.create('Ext.chart.Chart', {
  27. id: 'chartCmp',
  28. xtype: 'chart',
  29. animate: true,
  30. shadow: true,
  31. store: store1,
  32. axes: [{
  33. type: 'Numeric',
  34. position: 'bottom',
  35. fields: ['data1'],
  36. label: {
  37. renderer: Ext.util.Format.numberRenderer('0,0')
  38. },
  39. title: 'Number of Hits',
  40. grid: true,
  41. minimum: 0
  42. }, {
  43. type: 'Category',
  44. position: 'left',
  45. fields: ['name'],
  46. title: 'Month of the Year'
  47. }],
  48. theme: 'White',
  49. background: {
  50. gradient: {
  51. id: 'backgroundGradient',
  52. angle: 45,
  53. stops: {
  54. 0: {
  55. color: '#ffffff'
  56. },
  57. 100: {
  58. color: '#eaf1f8'
  59. }
  60. }
  61. }
  62. },
  63. series: [{
  64. type: 'bar',
  65. axis: 'bottom',
  66. highlight: true,
  67. tips: {
  68. trackMouse: true,
  69. width: 140,
  70. height: 28,
  71. renderer: function(storeItem, item) {
  72. this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data1') + ' views');
  73. }
  74. },
  75. label: {
  76. display: 'insideEnd',
  77. field: 'data1',
  78. renderer: Ext.util.Format.numberRenderer('0'),
  79. orientation: 'horizontal',
  80. color: '#333',
  81. 'text-anchor': 'middle'
  82. },
  83. xField: 'name',
  84. yField: ['data1']
  85. }]
  86. });
  87. var win = Ext.create('Ext.Window', {
  88. width: 800,
  89. height: 600,
  90. minHeight: 400,
  91. minWidth: 550,
  92. hidden: false,
  93. maximizable: true,
  94. title: 'Bar Chart',
  95. renderTo: Ext.getBody(),
  96. layout: 'fit',
  97. tbar: [{
  98. text: 'Save Chart',
  99. handler: function() {
  100. Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  101. if(choice == 'yes'){
  102. chart.save({
  103. type: 'image/png'
  104. });
  105. }
  106. });
  107. }
  108. }, {
  109. text: 'Reload Data',
  110. handler: function() {
  111. store1.loadData(generateData());
  112. }
  113. }],
  114. items: chart
  115. });
  116. });