Column2.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. store1.loadData(generateData(5, 0));
  5. var colors = ['url(#v-1)',
  6. 'url(#v-2)',
  7. 'url(#v-3)',
  8. 'url(#v-4)',
  9. 'url(#v-5)'];
  10. var baseColor = '#eee';
  11. Ext.define('Ext.chart.theme.Fancy', {
  12. extend: 'Ext.chart.theme.Base',
  13. constructor: function(config) {
  14. this.callParent([Ext.apply({
  15. axis: {
  16. fill: baseColor,
  17. stroke: baseColor
  18. },
  19. axisLabelLeft: {
  20. fill: baseColor
  21. },
  22. axisLabelBottom: {
  23. fill: baseColor
  24. },
  25. axisTitleLeft: {
  26. fill: baseColor
  27. },
  28. axisTitleBottom: {
  29. fill: baseColor
  30. },
  31. colors: colors
  32. }, config)]);
  33. }
  34. });
  35. var chart = Ext.create('Ext.chart.Chart', {
  36. id: 'chartCmp',
  37. xtype: 'chart',
  38. theme: 'Fancy',
  39. animate: {
  40. easing: 'bounceOut',
  41. duration: 750
  42. },
  43. store: store1,
  44. background: {
  45. fill: 'rgb(17, 17, 17)'
  46. },
  47. gradients: [
  48. {
  49. 'id': 'v-1',
  50. 'angle': 0,
  51. stops: {
  52. 0: {
  53. color: 'rgb(212, 40, 40)'
  54. },
  55. 100: {
  56. color: 'rgb(117, 14, 14)'
  57. }
  58. }
  59. },
  60. {
  61. 'id': 'v-2',
  62. 'angle': 0,
  63. stops: {
  64. 0: {
  65. color: 'rgb(180, 216, 42)'
  66. },
  67. 100: {
  68. color: 'rgb(94, 114, 13)'
  69. }
  70. }
  71. },
  72. {
  73. 'id': 'v-3',
  74. 'angle': 0,
  75. stops: {
  76. 0: {
  77. color: 'rgb(43, 221, 115)'
  78. },
  79. 100: {
  80. color: 'rgb(14, 117, 56)'
  81. }
  82. }
  83. },
  84. {
  85. 'id': 'v-4',
  86. 'angle': 0,
  87. stops: {
  88. 0: {
  89. color: 'rgb(45, 117, 226)'
  90. },
  91. 100: {
  92. color: 'rgb(14, 56, 117)'
  93. }
  94. }
  95. },
  96. {
  97. 'id': 'v-5',
  98. 'angle': 0,
  99. stops: {
  100. 0: {
  101. color: 'rgb(187, 45, 222)'
  102. },
  103. 100: {
  104. color: 'rgb(85, 10, 103)'
  105. }
  106. }
  107. }],
  108. axes: [{
  109. type: 'Numeric',
  110. position: 'left',
  111. fields: ['data1'],
  112. minimum: 0,
  113. maximum: 100,
  114. label: {
  115. renderer: Ext.util.Format.numberRenderer('0,0')
  116. },
  117. title: 'Number of Hits',
  118. grid: {
  119. odd: {
  120. stroke: '#555'
  121. },
  122. even: {
  123. stroke: '#555'
  124. }
  125. }
  126. }, {
  127. type: 'Category',
  128. position: 'bottom',
  129. fields: ['name'],
  130. title: 'Month of the Year'
  131. }],
  132. series: [{
  133. type: 'column',
  134. axis: 'left',
  135. highlight: true,
  136. label: {
  137. display: 'insideEnd',
  138. 'text-anchor': 'middle',
  139. field: 'data1',
  140. orientation: 'horizontal',
  141. fill: '#fff',
  142. font: '17px Arial'
  143. },
  144. renderer: function(sprite, storeItem, barAttr, i, store) {
  145. barAttr.fill = colors[i % colors.length];
  146. return barAttr;
  147. },
  148. style: {
  149. opacity: 0.95
  150. },
  151. xField: 'name',
  152. yField: 'data1'
  153. }]
  154. });
  155. var win = Ext.create('Ext.Window', {
  156. width: 800,
  157. height: 600,
  158. minHeight: 400,
  159. minWidth: 550,
  160. hidden: false,
  161. maximizable: true,
  162. title: 'Column Chart',
  163. renderTo: Ext.getBody(),
  164. layout: 'fit',
  165. tbar: [{
  166. text: 'Save Chart',
  167. handler: function() {
  168. Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  169. if(choice == 'yes'){
  170. chart.save({
  171. type: 'image/png'
  172. });
  173. }
  174. });
  175. }
  176. }, {
  177. text: 'Reload Data',
  178. handler: function() {
  179. store1.loadData(generateData(5, 0));
  180. }
  181. }],
  182. items: chart
  183. });
  184. });