SaleTrend.js 6.4 KB

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