firstAccessPieChart.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="content">
  3. <!-- #ifdef APP-PLUS || H5 -->
  4. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" ref="chartId" :id="chartId" class="echarts"></view>
  5. <!-- #endif -->
  6. </view>
  7. </template>
  8. <script>
  9. import echarts from '../../static/echarts.js'
  10. let app = getApp();
  11. export default {
  12. props: {
  13. chartId: String,
  14. dataList: {
  15. type: Array,
  16. default: () => {
  17. return []
  18. }
  19. }
  20. },
  21. data() {
  22. return {
  23. data1: [],
  24. themeColor: null,
  25. fuzhuColor: null,
  26. themeColor50: null,
  27. themeColor25: null,
  28. fuzhuColor50: null,
  29. fuzhuColor15: null,
  30. option: {
  31. tooltip: {
  32. trigger: 'item',
  33. // formatter: '{a} <br/>{b} : {c} ({d}%)'
  34. // formatter: '{a} {b} :({d}%)'
  35. // trigger: 'item',
  36. align: 'auto'
  37. },
  38. color: [],
  39. series: {
  40. name: '',
  41. type: 'pie',
  42. radius: ['52%', '70%'],
  43. center: ['50%', '50%'],
  44. data: [],
  45. itemStyle: {
  46. normal: {
  47. // color: function(e) {
  48. // var colorList = [this.themeColor, this.fuzhuColor, this.themeColor25, this.themeColor50]
  49. // return colorList[e.dataIndex]
  50. // },
  51. label: {
  52. // formatter: function(e) {
  53. // return "" + e.name + "\n\n{d|" + e.des + "}"
  54. // },
  55. formatter: null,
  56. rich: {
  57. d: {
  58. fontSize: 14,
  59. color: "#000000"
  60. }
  61. }
  62. }
  63. },
  64. emphasis: {
  65. itemStyle: {
  66. shadowBlur: 10,
  67. shadowOffsetX: 0,
  68. shadowColor: 'rgba(0, 0, 0, 0.0)'
  69. }
  70. }
  71. }
  72. // emphasis: {
  73. // itemStyle: {
  74. // shadowBlur: 10,
  75. // shadowOffsetX: 0,
  76. // shadowColor: 'rgba(0, 0, 0, 0.5)'
  77. // }
  78. // }
  79. }
  80. },
  81. }
  82. },
  83. mounted() {
  84. this.themeColor = app.globalData.themeColor
  85. this.themeColor50 = app.globalData.themeColor50
  86. this.themeColor25 = app.globalData.themeColor25
  87. this.fuzhuColor = app.globalData.fuzhuColor
  88. this.fuzhuColor50 = app.globalData.fuzhuColor50
  89. this.fuzhuColor15 = app.globalData.fuzhuColor15
  90. this.getDataAction()
  91. },
  92. methods: {
  93. getDataAction() {
  94. // this.dataList = [{
  95. // name: '户型',
  96. // value: 460,
  97. // color: this.themeColor
  98. // },
  99. // {
  100. // name: '周边配置',
  101. // value: 280,
  102. // color: this.fuzhuColor
  103. // },
  104. // {
  105. // name: '智能化',
  106. // value: 120,
  107. // color: this.themeColor25
  108. // },
  109. // {
  110. // name: '面积',
  111. // value: 210,
  112. // color: this.themeColor50
  113. // }
  114. // ]
  115. this.data1 = this.dataList || []
  116. this.option.series.itemStyle.normal.color = null
  117. this.data1.forEach((item, index) => {
  118. item['color'] = ''
  119. item.name = item.name + item.des
  120. if (index == 0) {
  121. item.color = this.themeColor
  122. } else if (index == 1) {
  123. item.color = this.fuzhuColor
  124. } else if (index == 2) {
  125. item.color = this.themeColor50
  126. } else {
  127. item.color = this.themeColor25
  128. }
  129. })
  130. var tempData = this.data1
  131. var self = this
  132. this.option.series.data = tempData
  133. this.option.color = [this.themeColor, this.fuzhuColor, this.themeColor50, this.themeColor25]
  134. // this.option.series.itemStyle.normal.color = function(e) {
  135. // // console.log('color打印:', self.data1[e.dataIndex].color)
  136. // return self.data1[e.dataIndex].color
  137. // }
  138. // uni.showModal({
  139. // content: JSON.stringify(this.data1)
  140. // })
  141. // this.option.series.itemStyle.normal.label.formatter = function(e) {
  142. // // console.log('e:', e)
  143. // var obj = self.data1[e.dataIndex]
  144. // return "" + obj.name + "\n\n{d|" + (obj.value).toFixed(2) + "}"
  145. // }
  146. // this.chengjiaoNum = this.dataInfo.dealRateScore
  147. // this.yixiangNum = this.dataInfo.yxScore
  148. // this.bakongNum = this.dataInfo.bkScore
  149. // this.option.series[0].data[0].value = [this.chengjiaoNum, this.yixiangNum, this.bakongNum]
  150. // console.log('决策要素数据刷新', this.data1)
  151. },
  152. onViewClick(options) {
  153. // console.log(options)
  154. }
  155. },
  156. watch: {
  157. chartId: {
  158. handler(e) {
  159. // this.getDataAction()
  160. },
  161. immediate: true
  162. }
  163. }
  164. }
  165. </script>
  166. <script module="echarts" lang="renderjs">
  167. let myChart
  168. export default {
  169. mounted() {
  170. this.initAction()
  171. },
  172. methods: {
  173. initAction() {
  174. if (typeof window.echarts === 'function') {
  175. this.initEcharts()
  176. } else {
  177. // 动态引入较大类库避免影响页面展示
  178. const script = document.createElement('script')
  179. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  180. script.src = 'static/echarts.js'
  181. script.onload = this.initEcharts.bind(this)
  182. document.head.appendChild(script)
  183. }
  184. },
  185. initEcharts() {
  186. // console.log("initEcharts -> this.$refs", this.$refs.chartId.$el.id)
  187. myChart = echarts.init(document.getElementById(this.$refs.chartId.$el.id))
  188. // 观测更新的数据在 view 层可以直接访问到
  189. if (myChart) myChart.setOption(this.option)
  190. },
  191. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  192. // 监听 service 层数据变更
  193. if (myChart) myChart.setOption(newValue)
  194. },
  195. onClick(event, ownerInstance) {
  196. // 调用 service 层的方法
  197. ownerInstance.callMethod('onViewClick', {
  198. test: 'test'
  199. })
  200. }
  201. }
  202. }
  203. </script>
  204. <style scoped lang="scss">
  205. .content {
  206. width: 100%;
  207. height: 100%;
  208. position: relative;
  209. font-size: 60rpx;
  210. font-family: DIN Alternate;
  211. font-weight: bold;
  212. .echarts {
  213. width: 100%;
  214. height: 100%;
  215. }
  216. }
  217. </style>