chart3.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="content">
  3. <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts3" class="echarts"></view>
  4. </view>
  5. </template>
  6. <script>
  7. //start
  8. //end
  9. export default {
  10. props:{
  11. bindData:{
  12. type:Object,
  13. default: ''
  14. }
  15. },
  16. data() {
  17. return {
  18. option: {
  19. // legend: {
  20. // data: ['bar', 'bar2', 'bar3', 'bar4'],
  21. // color: ['#1ECC22', '#0FC6C8','#0D88F0', '#FF1313', '#FF522A' ],
  22. // },
  23. grid: { //aa位置
  24. top: '2%',
  25. right: '8%',
  26. bottom: '1%',
  27. left: '17%',
  28. },
  29. color: ['#1ECC22', '#0FC6C8','#0D88F0', '#FF1313', '#FF522A' ],
  30. xAxis: [{
  31. show: false
  32. }],
  33. yAxis: [{ //aay轴
  34. axisTick: 'none',
  35. axisLine: 'none',
  36. axisLabel: {
  37. verticalAlign: 'bottom',
  38. align: 'bottom',
  39. padding: [0, 0, 8, 5],
  40. textStyle: {
  41. color: '#333',
  42. fontSize:'16'
  43. }
  44. },
  45. data: ['正常','其他','预警','故障','离线' ],
  46. },
  47. {
  48. //左侧柱状图的Y轴
  49. axisTick: 'none',
  50. axisLine: 'none',
  51. data: [this.bindData.normalCount,this.bindData.otherCount,this.bindData.earlyWarningCount,this.bindData.earlyWarningCount,this.bindData.offlineCount],
  52. axisLabel: {
  53. show: true,
  54. verticalAlign: 'bottom',
  55. align: 'right',
  56. padding: [0, 10, 8, 0],
  57. textStyle: {
  58. color: '#333',
  59. fontSize:'15'
  60. },
  61. formatter: function(value) {
  62. return value
  63. }
  64. }
  65. },
  66. ],
  67. series: [{
  68. type: 'bar',
  69. data: [this.bindData.normalCount, , , , ],
  70. barWidth: 6,
  71. itemStyle: {
  72. normal: {
  73. barBorderRadius: 6,
  74. }
  75. },
  76. z: 2
  77. }, {
  78. type: 'bar',
  79. data: [ ,this.bindData.otherCount, , , ],
  80. barWidth: 6,
  81. itemStyle: {
  82. normal: {
  83. barBorderRadius: 6,
  84. }
  85. },
  86. z: 2
  87. }, {
  88. type: 'bar',
  89. data: [ , ,this.bindData.earlyWarningCount, , ],
  90. barWidth: 6,
  91. itemStyle: {
  92. normal: {
  93. barBorderRadius: 6,
  94. }
  95. },
  96. z: 2
  97. },
  98. {
  99. type: 'bar',
  100. data: [ , , ,this.bindData.faultCount, ],
  101. barWidth: 6,
  102. itemStyle: {
  103. normal: {
  104. barBorderRadius: 6,
  105. }
  106. },
  107. z: 2
  108. },
  109. {
  110. type: 'bar',
  111. data: [ , , , ,this.bindData.offlineCount],
  112. barWidth: 6,
  113. itemStyle: {
  114. normal: {
  115. barBorderRadius: 6,
  116. }
  117. },
  118. z: 2
  119. },
  120. {
  121. type: 'bar',
  122. barGap: '-100%',
  123. data: [1000, 1000, 1000, 1000, 1000],
  124. barWidth: 6,
  125. itemStyle: {
  126. normal: {
  127. color: 'rgba(0,0,0, 0.15)',
  128. barBorderRadius: 6,
  129. }
  130. },
  131. z: 0
  132. },
  133. ]
  134. }
  135. }
  136. },
  137. computed: {
  138. // total:function(){
  139. // return parseInt(this.bindData.normalCount)+3
  140. // },
  141. // onePersent:function(){
  142. // return parseInt(1/this.total*100)
  143. // },
  144. },
  145. onLoad() {
  146. // this.option.series.reverse()
  147. },
  148. methods: {
  149. changeOption() {
  150. const data = this.option.series[0].data
  151. // 随机更新示例数据
  152. data.forEach((item, index) => {
  153. data.splice(index, 1, Math.random() * 40)
  154. })
  155. },
  156. onViewClick(options) {
  157. console.log(options)
  158. }
  159. }
  160. }
  161. </script>
  162. <script module="echarts" lang="renderjs">
  163. let myChart
  164. export default {
  165. mounted() {
  166. if (typeof window.echarts === 'function') {
  167. this.initEcharts()
  168. } else {
  169. // 动态引入较大类库避免影响页面展示
  170. const script = document.createElement('script')
  171. // view 层的页面运行在 www 根目录,其相对路径相对于 www 计算
  172. script.src = '/static/echarts.min.js'
  173. script.onload = this.initEcharts.bind(this)
  174. document.head.appendChild(script)
  175. }
  176. },
  177. methods: {
  178. initEcharts() {
  179. myChart = echarts.init(document.getElementById('echarts3'))
  180. // 观测更新的数据在 view 层可以直接访问到
  181. myChart.setOption(this.option)
  182. },
  183. updateEcharts(newValue, oldValue, ownerInstance, instance) {
  184. // 监听 service 层数据变更
  185. myChart.setOption(newValue)
  186. },
  187. onClick(event, ownerInstance) {
  188. // 调用 service 层的方法
  189. ownerInstance.callMethod('onViewClick', {
  190. test: 'test'
  191. })
  192. }
  193. }
  194. }
  195. </script>
  196. <style>
  197. .content {
  198. display: flex;
  199. flex-direction: column;
  200. align-items: center;
  201. justify-content: center;
  202. }
  203. .echarts {
  204. width: 100%;
  205. height: 500rpx;
  206. margin-top: 70rpx;
  207. /* background:pink */
  208. }
  209. </style>