ReloadChart.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. Ext.require('Ext.chart.*');
  2. Ext.require(['Ext.layout.container.Fit', 'Ext.window.MessageBox']);
  3. Ext.onReady(function () {
  4. var chart = Ext.create('Ext.chart.Chart', {
  5. xtype: 'chart',
  6. animate: true,
  7. shadow: true,
  8. store: store1,
  9. axes: [{
  10. type: 'Numeric',
  11. position: 'left',
  12. fields: ['data1'],
  13. title: 'Hits',
  14. grid: true,
  15. minimum: 0,
  16. maximum: 100
  17. }, {
  18. type: 'Category',
  19. position: 'bottom',
  20. fields: ['name'],
  21. title: 'Months',
  22. label: {
  23. rotate: {
  24. degrees: 270
  25. }
  26. }
  27. }],
  28. series: [{
  29. type: 'column',
  30. axis: 'left',
  31. gutter: 80,
  32. xField: 'name',
  33. yField: ['data1'],
  34. tips: {
  35. trackMouse: true,
  36. width: 74,
  37. height: 38,
  38. renderer: function(storeItem, item) {
  39. this.setTitle(storeItem.get('name'));
  40. this.update(storeItem.get('data1'));
  41. }
  42. },
  43. style: {
  44. fill: '#38B8BF'
  45. }
  46. }]
  47. });
  48. var panel1 = Ext.create('widget.panel', {
  49. width: 800,
  50. height: 400,
  51. title: 'Column Chart with Reload - Hits per Month',
  52. renderTo: Ext.getBody(),
  53. layout: 'fit',
  54. tbar: [{
  55. text: 'Save Chart',
  56. handler: function() {
  57. Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  58. if(choice == 'yes'){
  59. chart.save({
  60. type: 'image/png'
  61. });
  62. }
  63. });
  64. }
  65. }, {
  66. text: 'Reload Data',
  67. handler: function() {
  68. store1.loadData(generateData());
  69. }
  70. }],
  71. items: chart
  72. });
  73. });