StackedBar.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Ext.require('Ext.chart.*');
  2. Ext.require(['Ext.layout.container.Fit', 'Ext.window.MessageBox']);
  3. Ext.onReady(function () {
  4. var store = Ext.create('Ext.data.JsonStore', {
  5. fields: ['year', 'comedy', 'action', 'drama', 'thriller'],
  6. data: [
  7. {year: 2005, comedy: 34000000, action: 23890000, drama: 18450000, thriller: 20060000},
  8. {year: 2006, comedy: 56703000, action: 38900000, drama: 12650000, thriller: 21000000},
  9. {year: 2007, comedy: 42100000, action: 50410000, drama: 25780000, thriller: 23040000},
  10. {year: 2008, comedy: 38910000, action: 56070000, drama: 24810000, thriller: 26940000}
  11. ]
  12. });
  13. var chart = Ext.create('Ext.chart.Chart',{
  14. xtype: 'chart',
  15. animate: true,
  16. shadow: true,
  17. store: store,
  18. legend: {
  19. position: 'right'
  20. },
  21. axes: [{
  22. type: 'Numeric',
  23. position: 'bottom',
  24. fields: ['comedy', 'action', 'drama', 'thriller'],
  25. title: false,
  26. grid: true,
  27. label: {
  28. renderer: function(v) {
  29. return String(v).replace(/(.)00000$/, '.$1M');
  30. }
  31. }
  32. }, {
  33. type: 'Category',
  34. position: 'left',
  35. fields: ['year'],
  36. title: false
  37. }],
  38. series: [{
  39. type: 'bar',
  40. axis: 'bottom',
  41. gutter: 80,
  42. xField: 'year',
  43. yField: ['comedy', 'action', 'drama', 'thriller'],
  44. stacked: true,
  45. tips: {
  46. trackMouse: true,
  47. width: 65,
  48. height: 28,
  49. renderer: function(storeItem, item) {
  50. this.setTitle(String(item.value[1] / 1000000) + 'M');
  51. }
  52. }
  53. }]
  54. });
  55. var panel1 = Ext.create('widget.panel', {
  56. width: 800,
  57. height: 400,
  58. title: 'Stacked Bar Chart - Movies by Genre',
  59. renderTo: Ext.getBody(),
  60. layout: 'fit',
  61. tbar: [{
  62. text: 'Save Chart',
  63. handler: function() {
  64. Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
  65. if(choice == 'yes'){
  66. chart.save({
  67. type: 'image/png'
  68. });
  69. }
  70. });
  71. }
  72. }],
  73. items: chart
  74. });
  75. });