SaleTrend.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. fillStyle: '#485465',
  35. },
  36. style: {
  37. fill: '#F7F8FA',
  38. strokeStyle: 'transparent'
  39. },
  40. renderer: me.categoryRender
  41. },{
  42. type: 'numeric',
  43. fields: ['sale', 'saleback'],
  44. position: 'left',
  45. grid: {
  46. even: {
  47. stroke: '#F7F8FA',
  48. },
  49. odd: {
  50. stroke: '#F7F8FA',
  51. }
  52. },
  53. label: {
  54. fillStyle: '#485465',
  55. },
  56. style: {
  57. fill: '#fff',
  58. strokeStyle: 'transparent'
  59. },
  60. }],
  61. series: [{
  62. type: 'line',
  63. smooth: true,
  64. title: '销售额',
  65. xField: 'x',
  66. yField: 'sale',
  67. label: {
  68. field: 'sale',
  69. display: 'over',
  70. fontSize: '12px',
  71. strokeStyle: '#A3D0EE',
  72. },
  73. marker: {
  74. radius: 0,
  75. lineWidth: 0
  76. },
  77. highlight: {
  78. fillStyle: '#53A8E2',
  79. fillOpacity: 1,
  80. strokeStyle: '#A3D0EE',
  81. radius: 5,
  82. lineWidth: 2,
  83. },
  84. style: {
  85. lineWidth: 2,
  86. fillStyle: '#53A8E2',
  87. fillOpacity: 0.1,
  88. },
  89. tooltip: {
  90. trackMouse: true,
  91. renderer: me.onSeriesTooltipRender
  92. },
  93. // renderer: me.onSeriesRenderer
  94. }, {
  95. type: 'line',
  96. smooth: true,
  97. title: '销售回款',
  98. xField: 'x',
  99. yField: 'saleback',
  100. label: {
  101. field: 'saleback',
  102. display: 'over',
  103. fontSize: '12px',
  104. strokeStyle: '#D54F65',
  105. },
  106. tooltip: {
  107. trackMouse: true,
  108. renderer: me.onSeriesTooltipRender
  109. },
  110. marker: {
  111. radius: 0,
  112. lineWidth: 0
  113. },
  114. highlight: {
  115. fillStyle: '#D54F65',
  116. fillOpacity: 1,
  117. strokeStyle: '#FF9BAC',
  118. radius: 5,
  119. lineWidth: 2,
  120. },
  121. style: {
  122. lineWidth: 2,
  123. fillStyle: '#D54F65',
  124. fillOpacity: 0.1,
  125. },
  126. }],
  127. listeners: {
  128. itemhighlightchange: me.itemhighlightchange
  129. }
  130. }]
  131. });
  132. me.callParent(arguments);
  133. },
  134. onSeriesRender: function (sprite, config, rendererData, index) {
  135. var store = rendererData.store,
  136. storeItems = store.getData().items,
  137. currentRecord = storeItems[index],
  138. previousRecord = (index > 0 ? storeItems[index-1] : currentRecord),
  139. current = currentRecord && currentRecord.data['g1'],
  140. previous = previousRecord && previousRecord.data['g1'],
  141. isUp = current >= previous,
  142. changes = {};
  143. switch (config.type) {
  144. case 'marker':
  145. changes.strokeStyle = (isUp ? 'cornflowerblue' : 'tomato');
  146. changes.fillStyle = (isUp ? 'aliceblue' : 'lightpink');
  147. break;
  148. case 'line':
  149. changes.strokeStyle = (isUp ? 'cornflowerblue' : 'tomato');
  150. changes.fillStyle = (isUp ? 'rgba(100, 149, 237, 0.4)' : 'rgba(255, 99, 71, 0.4)');
  151. break;
  152. }
  153. return changes;
  154. },
  155. onSeriesTooltipRender: function (tooltip, record, item) {
  156. tooltip.setHtml(record.get('x') + '月: ' + record.get(item.series.getYField()) + '万元');
  157. },
  158. categoryRender: function(axis, label, layoutContext, lastLabel) {
  159. return label + '月';
  160. },
  161. itemhighlightchange: function(chart, newHighlightItem, oldHighlightItem) {
  162. this.setSeriesLineWidth(newHighlightItem, 4);
  163. this.setSeriesLineWidth(oldHighlightItem, 2);
  164. },
  165. setSeriesLineWidth: function (item, lineWidth) {
  166. console.log('xxxx');
  167. if (item) {
  168. item.series.setStyle({
  169. lineWidth: lineWidth
  170. });
  171. }
  172. },
  173. });