SaleTrend.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. Ext.define('saas.view.home.charts.SaleTrend', {
  2. extend: 'saas.view.core.chart.ChartBase',
  3. xtype: 'sale-trend',
  4. id: 'sale_trend',
  5. bind: {
  6. title: '近六月销售趋势图(万元)'
  7. },
  8. initComponent: function() {
  9. var me = this;
  10. Ext.apply(me, {
  11. items: [{
  12. xtype: 'cartesian',
  13. colors: [
  14. '#64B0E4',
  15. '#FF1038'
  16. ],
  17. bind: {
  18. insetPadding: '{insetPadding}',
  19. store: '{sale_trend}',
  20. },
  21. // legend: {
  22. // type: 'dom',
  23. // docked: 'top',
  24. // },
  25. axes: [{
  26. // title: {
  27. // text: '月',
  28. // fontSize: 14,
  29. // },
  30. type: 'category',
  31. fields: ['x'],
  32. position: 'bottom',
  33. label: {
  34. fontSize: '12px',
  35. fillStyle: '#485465',
  36. },
  37. style: {
  38. fill: '#E5EAEF',
  39. strokeStyle: 'transparent'
  40. },
  41. renderer: me.categoryRender
  42. },{
  43. type: 'numeric',
  44. fields: ['sale', 'saleback'],
  45. position: 'left',
  46. grid: {
  47. even: {
  48. stroke: '#E5EAEF',
  49. },
  50. odd: {
  51. stroke: '#E5EAEF',
  52. }
  53. },
  54. label: {
  55. fontSize: '12px',
  56. fillStyle: '#485465',
  57. },
  58. style: {
  59. fill: '#fff',
  60. strokeStyle: 'transparent'
  61. },
  62. }],
  63. series: [{
  64. type: 'line',
  65. // smooth: true,
  66. title: '销售额',
  67. xField: 'x',
  68. yField: 'sale',
  69. label: {
  70. field: 'sale',
  71. display: 'over',
  72. fontSize: '12px',
  73. strokeStyle: '#A3D0EE',
  74. },
  75. marker: {
  76. radius: 0,
  77. lineWidth: 0
  78. },
  79. highlight: {
  80. fillStyle: '#53A8E2',
  81. fillOpacity: 1,
  82. strokeStyle: '#A3D0EE',
  83. radius: 5,
  84. lineWidth: 2,
  85. },
  86. style: {
  87. lineWidth: 2,
  88. fillStyle: '#53A8E2',
  89. fillOpacity: 0.1,
  90. },
  91. tooltip: {
  92. trackMouse: true,
  93. renderer: me.onSeriesTooltipRender
  94. },
  95. // renderer: me.onSeriesRenderer
  96. }, {
  97. type: 'line',
  98. // smooth: true,
  99. title: '销售回款',
  100. xField: 'x',
  101. yField: 'saleback',
  102. label: {
  103. field: 'saleback',
  104. display: 'over',
  105. fontSize: '12px',
  106. strokeStyle: '#D54F65',
  107. },
  108. tooltip: {
  109. trackMouse: true,
  110. renderer: me.onSeriesTooltipRender
  111. },
  112. marker: {
  113. radius: 0,
  114. lineWidth: 0
  115. },
  116. highlight: {
  117. fillStyle: '#D54F65',
  118. fillOpacity: 1,
  119. strokeStyle: '#FF9BAC',
  120. radius: 5,
  121. lineWidth: 2,
  122. },
  123. style: {
  124. lineWidth: 2,
  125. fillStyle: '#D54F65',
  126. fillOpacity: 0.1,
  127. },
  128. }],
  129. legend: {
  130. type: 'dom',
  131. docked: 'top',
  132. padding: 0,
  133. bodyPadding: 0,
  134. border: 0,
  135. cls: 'x-saletrend-legend'
  136. },
  137. listeners: {
  138. itemhighlightchange: me.itemhighlightchange
  139. }
  140. }]
  141. });
  142. me.callParent(arguments);
  143. },
  144. onSeriesRender: function (sprite, config, rendererData, index) {
  145. var store = rendererData.store,
  146. storeItems = store.getData().items,
  147. currentRecord = storeItems[index],
  148. previousRecord = (index > 0 ? storeItems[index-1] : currentRecord),
  149. current = currentRecord && currentRecord.data['g1'],
  150. previous = previousRecord && previousRecord.data['g1'],
  151. isUp = current >= previous,
  152. changes = {};
  153. switch (config.type) {
  154. case 'marker':
  155. changes.strokeStyle = (isUp ? 'cornflowerblue' : 'tomato');
  156. changes.fillStyle = (isUp ? 'aliceblue' : 'lightpink');
  157. break;
  158. case 'line':
  159. changes.strokeStyle = (isUp ? 'cornflowerblue' : 'tomato');
  160. changes.fillStyle = (isUp ? 'rgba(100, 149, 237, 0.4)' : 'rgba(255, 99, 71, 0.4)');
  161. break;
  162. }
  163. return changes;
  164. },
  165. onSeriesTooltipRender: function (tooltip, record, item) {
  166. tooltip.setHtml(record.get('x') + '月: ' + Ext.util.Format.number(record.get(item.series.getYField()), '0,000.00') + '万元');
  167. },
  168. categoryRender: function(axis, label, layoutContext, lastLabel) {
  169. return label + '月';
  170. },
  171. itemhighlightchange: function(chart, newHighlightItem, oldHighlightItem) {
  172. this.setSeriesLineWidth(newHighlightItem, 4);
  173. this.setSeriesLineWidth(oldHighlightItem, 2);
  174. },
  175. setSeriesLineWidth: function (item, lineWidth) {
  176. console.log('xxxx');
  177. if (item) {
  178. item.series.setStyle({
  179. lineWidth: lineWidth
  180. });
  181. }
  182. },
  183. });