analysis.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/skinRecord/components/analysis/analysis.js
  2. import * as echarts from '../../../../components/local/ec-canvas/echarts'
  3. import { getPrePage } from '../../../../utils/util'
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. options: {
  9. addGlobalClass: true,
  10. },
  11. properties: {
  12. analysis: {
  13. type: Object,
  14. value: null,
  15. observer(newVal, oldVal) {
  16. if (newVal && this.data.current == 0) {
  17. console.log(this.data.current)
  18. this.init()
  19. }
  20. },
  21. },
  22. current: {
  23. type: String,
  24. value: '',
  25. observer(newVal) {
  26. if (this.data.analysis && newVal == 0) {
  27. this.init()
  28. }
  29. },
  30. },
  31. },
  32. /**
  33. * 组件的初始数据
  34. */
  35. data: {
  36. percent: 0,
  37. ec: {
  38. lazyLoad: true,
  39. },
  40. },
  41. lifetimes: {
  42. attached: function () {
  43. this.setData({
  44. percent: 80,
  45. })
  46. // this.init()
  47. },
  48. detached: function () {
  49. // 在组件实例被从页面节点树移除时执行
  50. },
  51. },
  52. /**
  53. * 组件的方法列表
  54. */
  55. methods: {
  56. init() {
  57. let radarVal = []
  58. let seriesVal = []
  59. this.data.analysis.data.forEach((item) => {
  60. radarVal.push({ name: item.name, max: 100 })
  61. seriesVal.push(item.score)
  62. })
  63. console.log(radarVal)
  64. console.log(seriesVal)
  65. this.ecComponent = this.selectComponent('#mychart-dom-bar')
  66. this.ecComponent.init((canvas, width, height, dpr) => {
  67. // 获取组件的 canvas、width、height 后的回调函数
  68. const chart = echarts.init(canvas, null, {
  69. width: width,
  70. height: height,
  71. devicePixelRatio: dpr, // new
  72. })
  73. var option = {
  74. backgroundColor: '#FFF8FB',
  75. color: ['#FA7D22', 'red'],
  76. xAxis: {
  77. show: false,
  78. },
  79. yAxis: {
  80. show: false,
  81. },
  82. radar: {
  83. shape: 'circle',
  84. splitNumber: 4,
  85. indicator: radarVal,
  86. axisName: {
  87. // formatter: '【{value}】',
  88. color: '#333333',
  89. fontSize: 10,
  90. },
  91. splitArea: {
  92. areaStyle: {
  93. color: [
  94. 'rgba(218, 252, 191, 0.35)',
  95. 'rgba(255, 233, 185, 0.34)',
  96. 'rgba(255, 226, 208, 0.36)',
  97. 'rgba(255, 237, 237, 0.43)',
  98. ],
  99. // shadowColor: 'rgba(0, 0, 0, 0.2)',
  100. // shadowBlur: 10
  101. },
  102. },
  103. axisLine: {
  104. lineStyle: {
  105. color: '#fff',
  106. },
  107. },
  108. splitLine: {
  109. lineStyle: {
  110. color: 'transparent',
  111. },
  112. },
  113. },
  114. series: [
  115. {
  116. name: '预算 vs 开销',
  117. type: 'radar',
  118. data: [
  119. {
  120. value: seriesVal,
  121. areaStyle: {
  122. color: '#FA7D22',
  123. },
  124. lineStyle: {
  125. type: 'dotted',
  126. },
  127. label: {
  128. show: true,
  129. formatter: function (params) {
  130. return params.value
  131. },
  132. },
  133. },
  134. // {
  135. // value: [300, 430, 150, 300, 420, 250],
  136. // name: '开销'
  137. // },
  138. ],
  139. },
  140. ],
  141. }
  142. chart.setOption(option)
  143. // 将图表实例绑定到 this 上,可以在其他成员函数(如 dispose)中访问
  144. this.chart = chart
  145. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  146. return chart
  147. })
  148. },
  149. goToDetail() {
  150. getPrePage().setData(
  151. {
  152. current: 2,
  153. },
  154. () => {
  155. wx.pageScrollTo({
  156. scrollTop: 0,
  157. duration: 300,
  158. })
  159. }
  160. )
  161. },
  162. },
  163. })