chart.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="content">
  3. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts2"
  4. class="echarts"></view>
  5. </view>
  6. </template>
  7. <script>
  8. let title = '总数';
  9. export default {
  10. props: {
  11. bindData: {
  12. type: Object,
  13. default: ''
  14. }
  15. },
  16. data() {
  17. console.log('bindData')
  18. console.log(this.bindData)
  19. return {
  20. option:{
  21. title: {
  22. text: '{name|' + parseInt(this.bindData.completion)+'%}\n{val|任务完成率}',
  23. x: 'center',
  24. y: 'center',
  25. textStyle: {
  26. rich: {
  27. name: {
  28. fontSize: 32,
  29. fontWeight: 'normal',
  30. color: '#24F0E4',
  31. fontFamily: 'IMPACT',
  32. padding: [8, 0]
  33. },
  34. val: {
  35. fontSize: 16,
  36. color: '#333333',
  37. }
  38. }
  39. }
  40. },
  41. color: ['#F4F5F7'],
  42. legend: {
  43. show: false,
  44. data: []
  45. },
  46. series: [{
  47. name: 'Line 1',
  48. type: 'pie',
  49. clockWise: true,
  50. radius: ['64%', '80%'],
  51. itemStyle: {
  52. normal: {
  53. label: {
  54. show: false
  55. },
  56. labelLine: {
  57. show: false
  58. }
  59. }
  60. },
  61. hoverAnimation: false,
  62. data: [{
  63. value: parseInt(this.bindData.completion),
  64. name: '',
  65. itemStyle: {
  66. normal: {
  67. color: { // 完成的圆环的颜色
  68. colorStops: [{
  69. offset: 0,
  70. color: '#0BA0D7' // 0% 处的颜色
  71. }, {
  72. offset: 1,
  73. color: '#24F0E4' // 100% 处的颜色
  74. }]
  75. },
  76. label: {
  77. show: false
  78. },
  79. labelLine: {
  80. show: false
  81. }
  82. }
  83. }
  84. }, {
  85. name: '',
  86. value: 100 - parseInt(this.bindData.completion)
  87. }]
  88. }]
  89. }
  90. }
  91. },
  92. onLoad() {},
  93. methods: {
  94. onViewClick(options) {
  95. console.log(options)
  96. }
  97. }
  98. }
  99. </script>
  100. <script module="echarts" lang="renderjs">
  101. let myChart
  102. export default {
  103. mounted() {
  104. if (typeof window.echarts === 'function') {
  105. this.initEcharts()
  106. } else {
  107. // 动态引入较大类库避免影响页面展示
  108. const script = document.createElement('script')
  109. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  110. script.src = 'static/echarts.min.js'
  111. script.onload = this.initEcharts.bind(this)
  112. document.head.appendChild(script)
  113. }
  114. },
  115. methods: {
  116. initEcharts() {
  117. myChart = echarts.init(document.getElementById('echarts2'))
  118. // 观测更新的数据在 view 层可以直接访问到
  119. myChart.setOption(this.option)
  120. },
  121. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  122. // 监听 service 层数据变更
  123. myChart.setOption(newValue)
  124. },
  125. onClick(event, ownerInstance) {
  126. // 调用 service 层的方法
  127. ownerInstance.callMethod('onViewClick', {
  128. test: 'test'
  129. })
  130. }
  131. }
  132. }
  133. </script>
  134. <style>
  135. .content {
  136. display: flex;
  137. flex-direction: column;
  138. align-items: center;
  139. justify-content: center;
  140. }
  141. .echarts {
  142. width: 100%;
  143. height: 400rpx;
  144. margin-top: 70rpx;
  145. }
  146. </style>