SaleTrend.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. tooltip: {
  71. trackMouse: true,
  72. renderer: me.onSeriesTooltipRender
  73. },
  74. type: 'line',
  75. smooth: true,
  76. xField: 'x',
  77. yField: 'sale',
  78. marker: {
  79. radius: 0,
  80. lineWidth: 0
  81. },
  82. highlight: {
  83. fillStyle: '#53A8E2',
  84. fillOpacity: 1,
  85. strokeStyle: '#A3D0EE',
  86. radius: 5,
  87. lineWidth: 2,
  88. },
  89. style: {
  90. lineWidth: 2,
  91. fillStyle: '#53A8E2',
  92. fillOpacity: 0.1,
  93. },
  94. // renderer: me.onSeriesRenderer
  95. }, {
  96. type: 'line',
  97. smooth: true,
  98. title: '销售回款',
  99. xField: 'x',
  100. yField: ['saleback'],
  101. tooltip: {
  102. trackMouse: true,
  103. renderer: me.onSeriesTooltipRender
  104. },
  105. marker: {
  106. radius: 0,
  107. lineWidth: 0
  108. },
  109. highlight: {
  110. fillStyle: '#D54F65',
  111. fillOpacity: 1,
  112. strokeStyle: '#FF9BAC',
  113. radius: 5,
  114. lineWidth: 2,
  115. },
  116. style: {
  117. lineWidth: 2,
  118. fillStyle: '#D54F65',
  119. fillOpacity: 0.1,
  120. },
  121. }],
  122. listeners: {
  123. itemhighlightchange: me.itemhighlightchange
  124. }
  125. }]
  126. });
  127. me.callParent(arguments);
  128. },
  129. onSeriesRender: function (sprite, config, rendererData, index) {
  130. var store = rendererData.store,
  131. storeItems = store.getData().items,
  132. currentRecord = storeItems[index],
  133. previousRecord = (index > 0 ? storeItems[index-1] : currentRecord),
  134. current = currentRecord && currentRecord.data['g1'],
  135. previous = previousRecord && previousRecord.data['g1'],
  136. isUp = current >= previous,
  137. changes = {};
  138. switch (config.type) {
  139. case 'marker':
  140. changes.strokeStyle = (isUp ? 'cornflowerblue' : 'tomato');
  141. changes.fillStyle = (isUp ? 'aliceblue' : 'lightpink');
  142. break;
  143. case 'line':
  144. changes.strokeStyle = (isUp ? 'cornflowerblue' : 'tomato');
  145. changes.fillStyle = (isUp ? 'rgba(100, 149, 237, 0.4)' : 'rgba(255, 99, 71, 0.4)');
  146. break;
  147. }
  148. return changes;
  149. },
  150. onSeriesTooltipRender: function (tooltip, record, item) {
  151. tooltip.setHtml(record.get('x') + '月: ' + record.get(item.series.getYField()) + '万元');
  152. },
  153. categoryRender: function(axis, label, layoutContext, lastLabel) {
  154. return label + '月';
  155. },
  156. itemhighlightchange: function(chart, newHighlightItem, oldHighlightItem) {
  157. this.setSeriesLineWidth(newHighlightItem, 4);
  158. this.setSeriesLineWidth(oldHighlightItem, 2);
  159. },
  160. setSeriesLineWidth: function (item, lineWidth) {
  161. console.log('xxxx');
  162. if (item) {
  163. item.series.setStyle({
  164. lineWidth: lineWidth
  165. });
  166. }
  167. },
  168. });