Area.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. store: store1,
  10. legend: {
  11. position: 'bottom'
  12. },
  13. axes: [{
  14. type: 'Numeric',
  15. grid: true,
  16. position: 'left',
  17. fields: ['data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7'],
  18. title: 'Number of Hits',
  19. grid: {
  20. odd: {
  21. opacity: 1,
  22. fill: '#ddd',
  23. stroke: '#bbb',
  24. 'stroke-width': 1
  25. }
  26. },
  27. minimum: 0,
  28. adjustMinimumByMajorUnit: 0
  29. }, {
  30. type: 'Category',
  31. position: 'bottom',
  32. fields: ['name'],
  33. title: 'Month of the Year',
  34. grid: true,
  35. label: {
  36. rotate: {
  37. degrees: 315
  38. }
  39. }
  40. }],
  41. series: [{
  42. type: 'area',
  43. highlight: false,
  44. axis: 'left',
  45. xField: 'name',
  46. yField: ['data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7'],
  47. style: {
  48. opacity: 0.93
  49. }
  50. }]
  51. });
  52. var win = Ext.create('Ext.Window', {
  53. width: 800,
  54. height: 600,
  55. minHeight: 400,
  56. minWidth: 550,
  57. hidden: false,
  58. shadow: false,
  59. maximizable: true,
  60. title: 'Area Chart',
  61. renderTo: Ext.getBody(),
  62. layout: 'fit',
  63. tbar: [{
  64. text: 'Save Chart',
  65. handler: function() {
  66. Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  67. if(choice == 'yes'){
  68. chart.save({
  69. type: 'image/png'
  70. });
  71. }
  72. });
  73. }
  74. }, {
  75. text: 'Reload Data',
  76. handler: function() {
  77. store1.loadData(generateData());
  78. }
  79. }, {
  80. enableToggle: true,
  81. pressed: true,
  82. text: 'Animate',
  83. toggleHandler: function(btn, pressed) {
  84. var chart = Ext.getCmp('chartCmp');
  85. chart.animate = pressed ? { easing: 'ease', duration: 500 } : false;
  86. }
  87. }],
  88. items: chart
  89. });
  90. });