NewAnalysisAdded.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. const _Http = getApp().globalData.http;
  2. import * as echarts from '../../ec-canvas/echarts';
  3. Component({
  4. options: {
  5. addGlobalClass: true
  6. },
  7. properties: {
  8. idname: {
  9. type: [String, Number]
  10. }
  11. },
  12. lifetimes: {
  13. attached: function () {
  14. getApp().globalData.Language.getLanguagePackage(this)
  15. this.setData({
  16. "content.dataid": wx.getStorageSync('userMsg').userid,
  17. "content.username": wx.getStorageSync('userMsg').name,
  18. })
  19. }
  20. },
  21. data: {
  22. year: new Date().getFullYear().toString(),
  23. "content": {
  24. enddate: new Date().toISOString().split('T')[0],
  25. where: {}
  26. }
  27. },
  28. methods: {
  29. async getList(init = false) {
  30. let content = this.data.content
  31. const {
  32. dataid,
  33. type,
  34. username,
  35. isleave
  36. } = getCurrentPages()[getCurrentPages().length - 1].data;
  37. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  38. content.dataid = dataid;
  39. content.type = type;
  40. content.username = username;
  41. content.where.isleave = isleave;
  42. _Http.basic({
  43. "id": this.data.idname,
  44. content
  45. }).then(res => {
  46. if (res.code != '1') return wx.showToast({
  47. title: res.data,
  48. icon: "none"
  49. })
  50. this.initChart(res.data)
  51. })
  52. },
  53. initChart(data) {
  54. console.log("data", data)
  55. const colors = ['#6CD2A1', '#5F9DFC', '#ECB937', '#F69240'],
  56. getMapText = getApp().globalData.Language.getMapText;
  57. let legend = [getMapText('去年同期新增'), getMapText('本期新增'), `${getMapText('同比增长率')}`],
  58. series = [{
  59. name: getMapText('去年同期新增'),
  60. type: 'bar',
  61. data: data.histogram.filter(v => v.type == '去年同期新增' || v.key == '去年同期新增').map(v => v.value),
  62. smooth: true
  63. },
  64. {
  65. name: getMapText('本期新增'),
  66. type: 'bar',
  67. yAxisIndex: 1,
  68. data: data.histogram.filter(v => v.type == '本期新增' || v.key == '本期新增').map(v => v.value),
  69. smooth: true
  70. },
  71. {
  72. name: getMapText('同比增长率'),
  73. type: 'line',
  74. yAxisIndex: 2,
  75. data: data.lineChart.map(v => this.data.idname == 20231018155804 ? (v.value).toFixed(2) : (v.value * 100).toFixed(2)),
  76. smooth: true
  77. }
  78. ]
  79. const option = {
  80. color: colors,
  81. tooltip: {
  82. trigger: 'axis',
  83. confine: true, // Ensure tooltip stays within the chart area
  84. formatter: function (params) {
  85. let tooltipText = '';
  86. params.forEach((item, index) => {
  87. tooltipText += `${index==0?item.axisValue+'\n':''}${item.marker}${item.seriesName}: ${item.value}${item.seriesName == getMapText('同比增长率')||item.seriesName == getMapText('准交率') ? '%' : ''}\n`;
  88. });
  89. return tooltipText;
  90. },
  91. textStyle: {
  92. fontSize: 10, // Reduced font size
  93. lineHeight: 14 // Adjusted line height for smaller tooltip height
  94. }
  95. },
  96. legend: {
  97. data: legend
  98. },
  99. xAxis: [{
  100. type: 'category',
  101. axisTick: {
  102. alignWithLabel: true
  103. },
  104. data: data.lineChart.map(v => v.date),
  105. axisLabel: {
  106. interval: 0,
  107. rotate: 45
  108. }
  109. }],
  110. yAxis: [{
  111. type: 'value',
  112. name: '',
  113. position: 'right',
  114. offset: 80,
  115. alignTicks: true,
  116. axisLine: {
  117. show: true,
  118. },
  119. axisLabel: {
  120. formatter: '{value}'
  121. }
  122. },
  123. {
  124. type: 'value',
  125. name: '',
  126. position: 'left',
  127. alignTicks: true,
  128. axisLine: {
  129. show: false,
  130. },
  131. axisLabel: {
  132. formatter: '{value}',
  133. rotate: 45
  134. }
  135. },
  136. {
  137. type: 'value',
  138. name: '',
  139. position: 'right',
  140. alignTicks: true,
  141. offset: 80,
  142. axisLine: {
  143. show: false,
  144. lineStyle: {
  145. color: colors[1]
  146. }
  147. },
  148. axisLabel: {
  149. formatter: '{value}'
  150. }
  151. },
  152. ],
  153. series
  154. };
  155. this.chartComponent = this.selectComponent('#mychart');
  156. this.chartComponent.init((canvas, width, height, dpr) => {
  157. const chart = echarts.init(canvas, null, {
  158. width,
  159. height,
  160. devicePixelRatio: dpr
  161. });
  162. chart.setOption(option);
  163. return chart;
  164. });
  165. },
  166. changeDate({
  167. detail
  168. }) {
  169. this.setData({
  170. "content.enddate": detail
  171. })
  172. this.getList(true)
  173. },
  174. }
  175. })