chart.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="content" >
  3. <view @click="echarts.onClick" :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: ['#00B7FC', '#935AF9', '#FF5354', '#FF8758', '#FFCF34', '#00E9CD', '#00B7FC'],
  19. title: {
  20. left: 'center'
  21. },
  22. tooltip: {
  23. trigger: 'item',
  24. // formatter: "{a} <br/>{b}: {c} ({d}%)"
  25. formatter: "{b}: {c} "
  26. },
  27. title: [{ //aa标题
  28. text: '{val|'+this.bindData.score+'}\n{name|' + title + '}',
  29. top: '45%',
  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. show:false,
  48. orient: 'horizontal',
  49. icon: 'circle',
  50. itemWidth: 12,
  51. itemHeight: 12,
  52. itemGap: 60,
  53. // top: -10,
  54. textStyle: {
  55. fontSize: 14,
  56. rich: {
  57. name: {
  58. fontSize: 18
  59. },
  60. value: {
  61. fontSize: 14,
  62. padding: [0, 20, 0, 5]
  63. },
  64. }
  65. },
  66. },
  67. series: [{
  68. name: '访问来源',
  69. type: 'pie',
  70. radius: ['40%', '60%'],
  71. center: ['50%', '55%'],
  72. itemStyle: {
  73. normal: {
  74. },
  75. },
  76. data: [{
  77. name: "RTU",
  78. value: this.bindData.count_rtu
  79. },
  80. {
  81. name: "电气火灾",
  82. value: this.bindData.count_dqhz
  83. },
  84. {
  85. name: "视频监测",
  86. value: this.bindData.count_spjc
  87. },
  88. {
  89. name: "水系统",
  90. value: this.bindData.count_sj
  91. },
  92. {
  93. name: "烟感",
  94. value: this.bindData.count_yg
  95. },
  96. {
  97. name: "消防栓",
  98. value: this.bindData.count_xfs
  99. },
  100. {
  101. name: "液位",
  102. value: this.bindData.count_rtu
  103. },
  104. ],
  105. labelLine: {
  106. normal: {
  107. length: 10, //aa折线长度
  108. length2: 20, //aa折线长度
  109. }
  110. },
  111. label: {
  112. normal: {
  113. formatter: '{b}:\n{d}%',
  114. }
  115. },
  116. }]
  117. }
  118. }
  119. },
  120. onLoad() {
  121. },
  122. methods: {
  123. changeOption() {
  124. const data = this.option.series[0].data
  125. // 随机更新示例数据
  126. data.forEach((item, index) => {
  127. data.splice(index, 1, Math.random() * 40)
  128. })
  129. },
  130. onViewClick(options) {
  131. console.log(options)
  132. }
  133. }
  134. }
  135. </script>
  136. <script module="echarts" lang="renderjs">
  137. let myChart
  138. export default {
  139. mounted() {
  140. if (typeof window.echarts === 'function') {
  141. this.initEcharts()
  142. } else {
  143. // 动态引入较大类库避免影响页面展示
  144. const script = document.createElement('script')
  145. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  146. script.src = 'static/echarts.min.js'
  147. script.onload = this.initEcharts.bind(this)
  148. document.head.appendChild(script)
  149. }
  150. },
  151. methods: {
  152. initEcharts() {
  153. myChart = echarts.init(document.getElementById('echarts2'))
  154. // 观测更新的数据在 view 层可以直接访问到
  155. myChart.setOption(this.option)
  156. },
  157. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  158. // 监听 service 层数据变更
  159. myChart.setOption(newValue)
  160. },
  161. onClick(event, ownerInstance) {
  162. // 调用 service 层的方法
  163. ownerInstance.callMethod('onViewClick', {
  164. test: 'test'
  165. })
  166. }
  167. }
  168. }
  169. </script>
  170. <style>
  171. .content {
  172. display: flex;
  173. flex-direction: column;
  174. align-items: center;
  175. justify-content: center;
  176. }
  177. .echarts {
  178. width: 100%;
  179. height: 500rpx;
  180. }
  181. </style>