chart-deviceReportingEvents.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. that.data_num = resp.data.num;
  29. that.data_reportor = resp.data.reportor
  30. that.myEcharts()
  31. })
  32. },
  33. myEcharts() {
  34. let that = this
  35. var chartDom = document.getElementById('forestfarm');
  36. var myChart = echarts.init(chartDom);
  37. var color = ['#02CDFF', '#62FBE7', '#7930FF', '#E148EB', '#ecb935']
  38. var option;
  39. option = {
  40. tooltip: {
  41. trigger: 'axis',
  42. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  43. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  44. }
  45. },
  46. grid: {
  47. left: '10%',
  48. right: '10%',
  49. bottom: '10%',
  50. top: '16%',
  51. containLabel: true
  52. },
  53. xAxis: {
  54. type: 'category',
  55. data:that.data_reportor,
  56. axisLine: {
  57. lineStyle: {
  58. color: '#1cc6a1'
  59. }
  60. },
  61. axisLabel: {
  62. // interval: 0,
  63. // rotate: 40,
  64. textStyle: {
  65. fontFamily: 'Microsoft YaHei'
  66. }
  67. },
  68. },
  69. yAxis: {
  70. type: 'value',
  71. max: '500',
  72. axisLine: {
  73. show: false,
  74. lineStyle: {
  75. color: '#19b1e8'
  76. }
  77. },
  78. splitLine: {
  79. show: true,
  80. lineStyle: {
  81. color: 'rgba(255,255,255,0.1)'
  82. }
  83. },
  84. axisLabel: {}
  85. },
  86. series: [{
  87. type: 'bar',
  88. barWidth: '15%',
  89. itemStyle: {
  90. normal: {
  91. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  92. offset: 0,
  93. color: '#fccb05'
  94. }, {
  95. offset: 1,
  96. color: '#1689f5'
  97. }]),
  98. barBorderRadius: 12,
  99. },
  100. },
  101. data: that.data_num
  102. }]
  103. };
  104. var app = {
  105. currentIndex: -1,
  106. };
  107. setInterval(function () {
  108. var dataLen = option.series[0].data.length;
  109. // 取消之前高亮的图形
  110. myChart.dispatchAction({
  111. type: 'downplay',
  112. seriesIndex: 0,
  113. dataIndex: app.currentIndex
  114. });
  115. app.currentIndex = (app.currentIndex + 1) % dataLen;
  116. //console.log(app.currentIndex);
  117. // 高亮当前图形
  118. myChart.dispatchAction({
  119. type: 'highlight',
  120. seriesIndex: 0,
  121. dataIndex: app.currentIndex,
  122. });
  123. // 显示 tooltip
  124. myChart.dispatchAction({
  125. type: 'showTip',
  126. seriesIndex: 0,
  127. dataIndex: app.currentIndex
  128. });
  129. }, 1000);
  130. option && myChart.setOption(option);
  131. },
  132. },
  133. }
  134. </script>
  135. <style rel="stylesheet/scss" lang="scss" scoped>
  136. .chart-container {
  137. width: 100%;
  138. height: auto;
  139. position: relative;
  140. padding-bottom: 10px;
  141. display: flex;
  142. }
  143. </style>