Pie.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. Ext.require('Ext.chart.*');
  2. Ext.require(['Ext.layout.container.Fit', 'Ext.window.MessageBox']);
  3. Ext.onReady(function () {
  4. store1.loadData(generateData(6, 20));
  5. var donut = false,
  6. chart = Ext.create('Ext.chart.Chart', {
  7. xtype: 'chart',
  8. id: 'chartCmp',
  9. animate: true,
  10. store: store1,
  11. shadow: true,
  12. legend: {
  13. position: 'right'
  14. },
  15. insetPadding: 60,
  16. theme: 'Base:gradients',
  17. series: [{
  18. type: 'pie',
  19. field: 'data1',
  20. showInLegend: true,
  21. donut: donut,
  22. tips: {
  23. trackMouse: true,
  24. width: 140,
  25. height: 28,
  26. renderer: function(storeItem, item) {
  27. //calculate percentage.
  28. var total = 0;
  29. store1.each(function(rec) {
  30. total += rec.get('data1');
  31. });
  32. this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('data1') / total * 100) + '%');
  33. }
  34. },
  35. highlight: {
  36. segment: {
  37. margin: 20
  38. }
  39. },
  40. label: {
  41. field: 'name',
  42. display: 'rotate',
  43. contrast: true,
  44. font: '18px Arial'
  45. }
  46. }]
  47. });
  48. var panel1 = Ext.create('widget.panel', {
  49. width: 800,
  50. height: 600,
  51. title: 'Semester Trends',
  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(6, 20));
  69. }
  70. }, {
  71. enableToggle: true,
  72. pressed: false,
  73. text: 'Donut',
  74. toggleHandler: function(btn, pressed) {
  75. var chart = Ext.getCmp('chartCmp');
  76. chart.series.first().donut = pressed ? 35 : false;
  77. chart.refresh();
  78. }
  79. }],
  80. items: chart
  81. });
  82. });