chart.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="content">
  3. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts">
  4. </view>
  5. </view>
  6. </template>
  7. <script>
  8. var dataname = ['消防水系统', '报警主机', '电气火灾', '其他', '监控视频']
  9. var color = ['#3C8BF0', '#06CDF8', '#0ECB70', '#6744EF', '#FFD803'];
  10. export default {
  11. name: 'chart',
  12. props: {
  13. fbindData: {
  14. type: Object,
  15. default: null
  16. },
  17. findicator:{
  18. type: Array,
  19. default: null
  20. },
  21. fdatavalue:{
  22. type: Array,
  23. default: null
  24. }
  25. },
  26. computed: {
  27. bindData() {
  28. return this.fbindData;
  29. },
  30. },
  31. data() {
  32. return {
  33. option: {
  34. tooltip: {
  35. formatter: () => {
  36. var html = '';
  37. [this.bindData.fire_water_count, this.bindData.alarm_host_count, this.bindData
  38. .electrical_fire_count, this.bindData.other_count, this.bindData
  39. .video_monitoring_count
  40. ].map((val, ind) => {
  41. html += dataname[ind] + ' : ' + val + '\n'
  42. })
  43. return html
  44. }
  45. },
  46. radar: {
  47. center: ["50%", "50%"],
  48. radius: "72%",
  49. splitArea: {
  50. areaStyle: {
  51. color: [
  52. '#6494fe', '#d1dfff',
  53. '#6494fe', '#d1dfff',
  54. ]
  55. }
  56. },
  57. axisLabel: {
  58. show: false,
  59. },
  60. axisLine: {
  61. show: true,
  62. lineStyle: {
  63. color: "rgba(255,255,255,.5)",
  64. }
  65. },
  66. splitLine: {
  67. lineStyle: {
  68. color: '#fff', // 分隔线颜色
  69. width: 1 // 分隔线线宽
  70. }
  71. },
  72. name: {
  73. formatter: (value) => {
  74. function contains(arrays, obj) {
  75. var i = arrays.length;
  76. while (i--) {
  77. if (arrays[i] === obj) {
  78. return i;
  79. }
  80. }
  81. return false;
  82. }
  83. var i = contains(dataname, value);
  84. var datavalue = [this.bindData.fire_water_count, this.bindData
  85. .alarm_host_count, this.bindData.electrical_fire_count, this.bindData
  86. .other_count, this.bindData.video_monitoring_count
  87. ]
  88. var percent = datavalue[i];
  89. return '{a|' + value + '}\n ' + '{b|' + percent + '}'
  90. },
  91. textStyle: {
  92. rich: {
  93. a: {
  94. // color: '#333',
  95. fontSize: 13,
  96. align: 'center',
  97. padding: [-5, 0, 0, 0]
  98. },
  99. b: {
  100. // color: 'red',
  101. fontSize: 13,
  102. align: 'center',
  103. padding: [-18, 0, 0, -7]
  104. }
  105. },
  106. },
  107. },
  108. indicator: this.findicator
  109. },
  110. series: [{
  111. type: "radar",
  112. symbol: "circle",
  113. symbolSize: 7,
  114. areaStyle: {
  115. normal: {
  116. color: 'rgba(255,2,2, 0.5)',
  117. },
  118. },
  119. itemStyle: {
  120. color: '#fff',
  121. borderColor: '#ff0202',
  122. borderWidth: 1,
  123. },
  124. lineStyle: {
  125. normal: {
  126. color: "#ff0202",
  127. width: 1
  128. }
  129. },
  130. data: [this.fdatavalue]
  131. }]
  132. }
  133. }
  134. },
  135. onLoad() {
  136. },
  137. methods: {
  138. onViewClick(options) {
  139. console.log(options)
  140. }
  141. }
  142. }
  143. </script>
  144. <script module="echarts" lang="renderjs">
  145. let myChart
  146. export default {
  147. mounted() {
  148. if (typeof window.echarts === 'function') {
  149. this.initEcharts()
  150. } else {
  151. // 动态引入较大类库避免影响页面展示
  152. const script = document.createElement('script')
  153. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  154. script.src = 'static/echarts.min.js'
  155. script.onload = this.initEcharts.bind(this)
  156. document.head.appendChild(script)
  157. }
  158. },
  159. methods: {
  160. initEcharts() {
  161. myChart = echarts.init(document.getElementById('echarts'))
  162. // 观测更新的数据在 view 层可以直接访问到
  163. myChart.setOption(this.option)
  164. },
  165. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  166. // 监听 service 层数据变更
  167. myChart.setOption(newValue)
  168. },
  169. onClick(event, ownerInstance) {
  170. // 调用 service 层的方法
  171. ownerInstance.callMethod('onViewClick', {
  172. test: 'test'
  173. })
  174. }
  175. }
  176. }
  177. </script>
  178. <style>
  179. .content {
  180. display: flex;
  181. flex-direction: column;
  182. align-items: center;
  183. justify-content: center;
  184. }
  185. .echarts {
  186. width: 100%;
  187. height: 500rpx;
  188. margin-top: 70rpx;
  189. /* background:pink */
  190. }
  191. </style>