chart2.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="content">
  3. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts2" class="echarts"></view>
  4. </view>
  5. </template>
  6. <script>
  7. let title = '报警总数';
  8. export default {
  9. props:{
  10. bindData:{
  11. type:Object,
  12. default: ''
  13. }
  14. },
  15. data() {
  16. return {
  17. option: {
  18. color: ['#006ED6', '#FF5354'],
  19. title: {
  20. left: 'center'
  21. },
  22. tooltip: {
  23. trigger: 'item',
  24. formatter: "{a}{b}:\n {c} ({d}%)"
  25. },
  26. title:false,
  27. // [{ //aa标题
  28. // text: '{val|' +(parseInt(this.bindData.wubao)+parseInt(this.bindData.unSolve)+ parseInt(this.bindData.truely))+ '}\n{name|' + title + '}',
  29. // top: '35%',
  30. // left: 'center',
  31. // textStyle: {
  32. // rich: {
  33. // name: {
  34. // fontSize: 14,
  35. // fontWeight: 'normal',
  36. // color: '#666666',
  37. // padding: [5, 0]
  38. // },
  39. // val: {
  40. // fontSize: 24,
  41. // color: '#333333',
  42. // }
  43. // }
  44. // }
  45. // }],
  46. legend: { //aa图例
  47. orient: 'horizontal',
  48. // icon: 'circle',
  49. itemWidth: 12,
  50. itemHeight: 12,
  51. itemGap: 20,
  52. bottom: -6,
  53. textStyle: {
  54. fontSize: 14,
  55. rich: {
  56. name: {
  57. fontSize: 18
  58. },
  59. value: {
  60. fontSize: 14,
  61. padding: [0, 20, 0, 5]
  62. },
  63. }
  64. },
  65. },
  66. series: [{
  67. name: '访问来源',
  68. type: 'pie',
  69. radius: ['40%', '60%'],
  70. center: ['50%', '45%'],
  71. itemStyle: {
  72. normal: {
  73. // shadowBlur: 20,
  74. // shadowColor: '#F9F5F7',
  75. // shadowOffsetX: 0,
  76. // shadowOffsetY: 0,
  77. },
  78. },
  79. data: [{
  80. name: "已处理",
  81. value: this.bindData.process_rate
  82. },
  83. {
  84. name: "未处理",
  85. value: this.bindData.unprocess
  86. },
  87. ],
  88. emphasis: {
  89. itemStyle: {
  90. shadowBlur: 10,
  91. shadowOffsetX: 0,
  92. // shadowColor: 'rgba(0, 0, 0, 0.5)'
  93. }
  94. },
  95. labelLine: {
  96. normal: {
  97. length: 10, //aa折线长度
  98. length2: 20, //aa折线长度
  99. }
  100. },
  101. label: {
  102. normal: {
  103. formatter: "{d}%"
  104. // formatter: params => {
  105. // var percent = 0;
  106. // var total = 0;
  107. // for (var i = 0; i < echartData.length; i++) {
  108. // total += echartData[i].value;
  109. // }
  110. // console.log(111);
  111. // console.log(total);
  112. // percent = ((params.value / total) * 100).toFixed(0);
  113. // return params.name + ': ' + percent + '%';
  114. // },
  115. }
  116. },
  117. }]
  118. }
  119. }
  120. },
  121. onLoad() {
  122. },
  123. methods: {
  124. changeOption() {
  125. const data = this.option.series[0].data
  126. // 随机更新示例数据
  127. data.forEach((item, index) => {
  128. data.splice(index, 1, Math.random() * 40)
  129. })
  130. },
  131. onViewClick(options) {
  132. console.log(options)
  133. }
  134. }
  135. }
  136. </script>
  137. <script module="echarts" lang="renderjs">
  138. let myChart
  139. export default {
  140. mounted() {
  141. if (typeof window.echarts === 'function') {
  142. this.initEcharts()
  143. } else {
  144. // 动态引入较大类库避免影响页面展示
  145. const script = document.createElement('script')
  146. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  147. script.src = 'static/echarts.min.js'
  148. script.onload = this.initEcharts.bind(this)
  149. document.head.appendChild(script)
  150. }
  151. },
  152. methods: {
  153. initEcharts() {
  154. myChart = echarts.init(document.getElementById('echarts2'))
  155. // 观测更新的数据在 view 层可以直接访问到
  156. myChart.setOption(this.option)
  157. },
  158. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  159. // 监听 service 层数据变更
  160. myChart.setOption(newValue)
  161. },
  162. onClick(event, ownerInstance) {
  163. // 调用 service 层的方法
  164. ownerInstance.callMethod('onViewClick', {
  165. test: 'test'
  166. })
  167. }
  168. }
  169. }
  170. </script>
  171. <style>
  172. .content {
  173. display: flex;
  174. flex-direction: column;
  175. align-items: center;
  176. justify-content: center;
  177. }
  178. .echarts {
  179. width: 100%;
  180. height: 500rpx;
  181. /* margin-bottom: 70rpx; */
  182. }
  183. </style>