chart-deviceReportingEvents.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!-- **************************************NO.5 林场*************************************** -->
  2. <template>
  3. <div class="chart-container">
  4. <div id="forestfarm" style="width: 100%; height:23vh;">
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. import * as echarts from 'echarts';
  10. import {getSbsbsjsl} from '@/api/bigdata.js'
  11. export default {
  12. name: 'forestfarm',
  13. data() {
  14. return {
  15. count: 0,
  16. data_num:[],
  17. data_reportor:[]
  18. }
  19. },
  20. mounted() {
  21. this.sjsbsbsl()
  22. },
  23. methods: {
  24. // 出处 http://192.144.199.210:8080/editor/index.html?chart_id=2nuQSYycLWN0P_EG
  25. sjsbsbsl() {
  26. let that = this
  27. getSbsbsjsl().then(resp => {
  28. console.log("设备上报事件数量", resp)
  29. that.data_num = resp.data.num;
  30. that.data_reportor = resp.data.reportor
  31. that.myEcharts()
  32. })
  33. },
  34. myEcharts() {
  35. let that = this
  36. var chartDom = document.getElementById('forestfarm');
  37. var myChart = echarts.init(chartDom);
  38. var color = ['#02CDFF', '#62FBE7', '#7930FF', '#E148EB', '#ecb935']
  39. var option;
  40. option = {
  41. tooltip: {
  42. trigger: 'axis',
  43. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  44. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  45. }
  46. },
  47. grid: {
  48. left: '10%',
  49. right: '10%',
  50. bottom: '10%',
  51. top: '16%',
  52. containLabel: true
  53. },
  54. xAxis: {
  55. type: 'category',
  56. data:that.data_reportor,
  57. axisLine: {
  58. lineStyle: {
  59. color: '#1cc6a1'
  60. }
  61. },
  62. axisLabel: {
  63. // interval: 0,
  64. // rotate: 40,
  65. textStyle: {
  66. fontFamily: 'Microsoft YaHei'
  67. }
  68. },
  69. },
  70. yAxis: {
  71. type: 'value',
  72. max: '500',
  73. axisLine: {
  74. show: false,
  75. lineStyle: {
  76. color: '#19b1e8'
  77. }
  78. },
  79. splitLine: {
  80. show: true,
  81. lineStyle: {
  82. color: 'rgba(255,255,255,0.1)'
  83. }
  84. },
  85. axisLabel: {}
  86. },
  87. series: [{
  88. type: 'bar',
  89. barWidth: '15%',
  90. itemStyle: {
  91. normal: {
  92. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  93. offset: 0,
  94. color: '#fccb05'
  95. }, {
  96. offset: 1,
  97. color: '#1689f5'
  98. }]),
  99. barBorderRadius: 12,
  100. },
  101. },
  102. data: that.data_num
  103. }]
  104. };
  105. var app = {
  106. currentIndex: -1,
  107. };
  108. setInterval(function () {
  109. var dataLen = option.series[0].data.length;
  110. // 取消之前高亮的图形
  111. myChart.dispatchAction({
  112. type: 'downplay',
  113. seriesIndex: 0,
  114. dataIndex: app.currentIndex
  115. });
  116. app.currentIndex = (app.currentIndex + 1) % dataLen;
  117. //console.log(app.currentIndex);
  118. // 高亮当前图形
  119. myChart.dispatchAction({
  120. type: 'highlight',
  121. seriesIndex: 0,
  122. dataIndex: app.currentIndex,
  123. });
  124. // 显示 tooltip
  125. myChart.dispatchAction({
  126. type: 'showTip',
  127. seriesIndex: 0,
  128. dataIndex: app.currentIndex
  129. });
  130. }, 1000);
  131. option && myChart.setOption(option);
  132. },
  133. },
  134. }
  135. </script>
  136. <style rel="stylesheet/scss" lang="scss" scoped>
  137. .chart-container {
  138. width: 100%;
  139. height: auto;
  140. position: relative;
  141. padding-bottom: 10px;
  142. display: flex;
  143. }
  144. </style>