ProjectChart.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. Ext.define('erp.view.plm.budget.ProjectChart',{
  2. extend: 'Ext.chart.Chart',
  3. alias: 'widget.ProjectChart',
  4. id: 'chartCmp',
  5. animate: true,
  6. store: Ext.create('Ext.data.Store',{
  7. fields: ['name', 'amount'],
  8. data:[]
  9. }),
  10. shadow: true,
  11. legend: {
  12. position: 'right',
  13. },
  14. insetPadding: 60,
  15. theme: 'Base:gradients',
  16. findid:null,
  17. BaseUtil: Ext.create('erp.util.BaseUtil'),
  18. series: [{
  19. type: 'pie',
  20. field: 'amount',
  21. showInLegend: true,
  22. // donut: donut,
  23. tips: {
  24. // trackMouse: true,
  25. width: 240,
  26. height: 28,
  27. renderer: function(storeItem, item) {
  28. var total=0;
  29. Ext.getCmp('chartCmp').store.each(function(rec) {
  30. total += Number(rec.get('amount'));
  31. });
  32. this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('amount') / total * 100) + '%' + ' 金额 :¥'+storeItem.get('amount'));
  33. }
  34. },
  35. highlight: {
  36. segment: {
  37. //margin: 20
  38. }
  39. },
  40. label: {
  41. field: 'name',
  42. display: 'rotate',
  43. contrast: true,
  44. font: '14px Arial'
  45. }
  46. }],
  47. initComponent : function(){
  48. var me=this;
  49. var id=Number(me.BaseUtil.getUrlParam('formCondition').split('IS')[1]);
  50. this.store.loadData(me.getChartData(id));
  51. this.callParent(arguments);
  52. },
  53. getChartData:function(id){
  54. var data=[];
  55. Ext.Ajax.request({//拿到grid的columns
  56. url : basePath + 'plm/budget/getData.action',
  57. params:{
  58. id:this.findid||id
  59. },
  60. async:false,
  61. method : 'post',
  62. callback : function(options,success,response){
  63. var res = new Ext.decode(response.responseText);
  64. if(res.success){
  65. data=Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  66. }
  67. }
  68. });
  69. return data;
  70. }
  71. });