Charts.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. Ext.require('Ext.chart.*');
  2. Ext.require(['Ext.layout.container.Fit', 'Ext.window.MessageBox']);
  3. Ext.onReady(function() {
  4. var downloadChart = function(chart){
  5. Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  6. if(choice == 'yes'){
  7. chart.save({
  8. type: 'image/png'
  9. });
  10. }
  11. });
  12. };
  13. var chart1 = Ext.create('Ext.chart.Chart',{
  14. xtype: 'chart',
  15. animate: false,
  16. store: store1,
  17. insetPadding: 30,
  18. axes: [{
  19. type: 'Numeric',
  20. minimum: 0,
  21. position: 'left',
  22. fields: ['data1'],
  23. title: false,
  24. grid: true,
  25. label: {
  26. renderer: Ext.util.Format.numberRenderer('0,0'),
  27. font: '10px Arial'
  28. }
  29. }, {
  30. type: 'Category',
  31. position: 'bottom',
  32. fields: ['name'],
  33. title: false,
  34. label: {
  35. font: '11px Arial',
  36. renderer: function(name) {
  37. return name.substr(0, 3) + ' 07';
  38. }
  39. }
  40. }],
  41. series: [{
  42. type: 'line',
  43. axis: 'left',
  44. xField: 'name',
  45. yField: 'data1',
  46. listeners: {
  47. itemmouseup: function(item) {
  48. Ext.example.msg('Item Selected', item.value[1] + ' visits on ' + Ext.Date.monthNames[item.value[0]]);
  49. }
  50. },
  51. tips: {
  52. trackMouse: true,
  53. width: 80,
  54. height: 40,
  55. renderer: function(storeItem, item) {
  56. this.setTitle(storeItem.get('name'));
  57. this.update(storeItem.get('data1'));
  58. }
  59. },
  60. style: {
  61. fill: '#38B8BF',
  62. stroke: '#38B8BF',
  63. 'stroke-width': 3
  64. },
  65. markerConfig: {
  66. type: 'circle',
  67. size: 4,
  68. radius: 4,
  69. 'stroke-width': 0,
  70. fill: '#38B8BF',
  71. stroke: '#38B8BF'
  72. }
  73. }]
  74. });
  75. var panel1 = Ext.create('widget.panel', {
  76. width: 600,
  77. height: 300,
  78. title: 'ExtJS.com Visits Trends, 2007/2008 (No styling)',
  79. renderTo: Ext.getBody(),
  80. layout: 'fit',
  81. tbar: [{
  82. text: 'Save Chart',
  83. handler: function(){ downloadChart(chart1); }
  84. }],
  85. items: chart1
  86. });
  87. var chart2 = Ext.create('Ext.chart.Chart',{
  88. xtype: 'chart',
  89. animate: false,
  90. store: store1,
  91. insetPadding: 30,
  92. axes: [{
  93. type: 'Numeric',
  94. minimum: 0,
  95. position: 'left',
  96. fields: ['data1'],
  97. title: false,
  98. grid: true,
  99. label: {
  100. renderer: Ext.util.Format.numberRenderer('0,0'),
  101. font: '10px Arial'
  102. }
  103. }, {
  104. type: 'Category',
  105. position: 'bottom',
  106. fields: ['name'],
  107. title: false,
  108. label: {
  109. font: '11px Arial',
  110. renderer: function(name) {
  111. return name.substr(0, 3);
  112. }
  113. }
  114. }],
  115. series: [{
  116. type: 'line',
  117. axis: 'left',
  118. xField: 'name',
  119. yField: 'data1',
  120. tips: {
  121. trackMouse: true,
  122. width: 110,
  123. height: 25,
  124. renderer: function(storeItem, item) {
  125. this.setTitle(storeItem.get('data1') + ' visits in ' + storeItem.get('name').substr(0, 3));
  126. }
  127. },
  128. style: {
  129. fill: '#38B8BF',
  130. stroke: '#38B8BF',
  131. 'stroke-width': 3
  132. },
  133. markerConfig: {
  134. type: 'circle',
  135. size: 4,
  136. radius: 4,
  137. 'stroke-width': 0,
  138. fill: '#38B8BF',
  139. stroke: '#38B8BF'
  140. }
  141. }]
  142. });
  143. var panel2 = Ext.create('widget.panel', {
  144. width: 600,
  145. height: 300,
  146. title: 'ExtJS.com Visits Trends, 2007/2008 (Simple styling)',
  147. renderTo: Ext.getBody(),
  148. layout: 'fit',
  149. tbar: [{
  150. text: 'Save Chart',
  151. handler: function(){ downloadChart(chart2); }
  152. }],
  153. items: chart2
  154. });
  155. var chart3 = Ext.create('Ext.chart.Chart', {
  156. xtype: 'chart',
  157. animate: false,
  158. store: store1,
  159. insetPadding: 30,
  160. gradients: [{
  161. angle: 90,
  162. id: 'bar-gradient',
  163. stops: {
  164. 0: {
  165. color: '#99BBE8'
  166. },
  167. 70: {
  168. color: '#77AECE'
  169. },
  170. 100: {
  171. color: '#77AECE'
  172. }
  173. }
  174. }],
  175. axes: [{
  176. type: 'Numeric',
  177. minimum: 0,
  178. maximum: 100,
  179. position: 'left',
  180. fields: ['data1'],
  181. title: false,
  182. grid: true,
  183. label: {
  184. renderer: Ext.util.Format.numberRenderer('0,0'),
  185. font: '10px Arial'
  186. }
  187. }, {
  188. type: 'Category',
  189. position: 'bottom',
  190. fields: ['name'],
  191. title: false,
  192. grid: true,
  193. label: {
  194. font: '11px Arial',
  195. renderer: function(name) {
  196. return name.substr(0, 3);
  197. }
  198. }
  199. }],
  200. series: [{
  201. type: 'column',
  202. axis: 'left',
  203. xField: 'name',
  204. yField: 'data1',
  205. style: {
  206. fill: 'url(#bar-gradient)',
  207. 'stroke-width': 3
  208. },
  209. markerConfig: {
  210. type: 'circle',
  211. size: 4,
  212. radius: 4,
  213. 'stroke-width': 0,
  214. fill: '#38B8BF',
  215. stroke: '#38B8BF'
  216. }
  217. }, {
  218. type: 'line',
  219. axis: 'left',
  220. xField: 'name',
  221. yField: 'data2',
  222. tips: {
  223. trackMouse: true,
  224. width: 110,
  225. height: 25,
  226. renderer: function(storeItem, item) {
  227. this.setTitle(storeItem.get('data2') + ' visits in ' + storeItem.get('name').substr(0, 3));
  228. }
  229. },
  230. style: {
  231. fill: '#18428E',
  232. stroke: '#18428E',
  233. 'stroke-width': 3
  234. },
  235. markerConfig: {
  236. type: 'circle',
  237. size: 4,
  238. radius: 4,
  239. 'stroke-width': 0,
  240. fill: '#18428E',
  241. stroke: '#18428E'
  242. }
  243. }]
  244. });
  245. var panel3 = Ext.create('widget.panel', {
  246. width: 600,
  247. height: 300,
  248. title: 'ExtJS.com Visits Trends, 2007/2008 (Full styling)',
  249. renderTo: Ext.getBody(),
  250. layout: 'fit',
  251. tbar: [{
  252. text: 'Save Chart',
  253. handler: function(){ downloadChart(chart3); }
  254. }],
  255. items: chart3
  256. });
  257. });