index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!--
  2. 描述: 仪表盘
  3. 作者: Jack Chen
  4. 日期: 2020-05-03
  5. -->
  6. <template>
  7. <div class="wrap-container sn-container">
  8. <div class="sn-content">
  9. <div class="sn-title">仪表盘</div>
  10. <div class="sn-body">
  11. <div class="wrap-container">
  12. <div class="chartsdom" id="chart_gauge"></div>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: `gauge`,
  21. data() {
  22. return {
  23. option: null,
  24. timer: null,
  25. }
  26. },
  27. mounted() {
  28. this.getEchart()
  29. },
  30. methods: {
  31. getEchart() {
  32. let myChart = echarts.init(document.getElementById(`chart_gauge`))
  33. this.option = {
  34. tooltip: {
  35. formatter: `{a} <br/>{c} {b}`,
  36. },
  37. series: [
  38. {
  39. name: `速度`,
  40. type: `gauge`,
  41. min: 0,
  42. max: 220,
  43. splitNumber: 11,
  44. // radius: '50%',
  45. axisLine: {
  46. // 坐标轴线
  47. lineStyle: {
  48. // 属性lineStyle控制线条样式
  49. color: [
  50. [0.09, `lime`],
  51. [0.82, `#1e90ff`],
  52. [1, `#ff4500`],
  53. ],
  54. width: 3,
  55. shadowColor: `#fff`, // 默认透明
  56. shadowBlur: 10,
  57. },
  58. },
  59. axisLabel: {
  60. // 坐标轴小标记
  61. fontWeight: `bolder`,
  62. color: `#fff`,
  63. shadowColor: `#fff`, // 默认透明
  64. shadowBlur: 10,
  65. },
  66. axisTick: {
  67. // 坐标轴小标记
  68. length: 15, // 属性length控制线长
  69. lineStyle: {
  70. // 属性lineStyle控制线条样式
  71. color: `auto`,
  72. shadowColor: `#fff`, // 默认透明
  73. shadowBlur: 10,
  74. },
  75. },
  76. splitLine: {
  77. // 分隔线
  78. length: 25, // 属性length控制线长
  79. lineStyle: {
  80. // 属性lineStyle(详见lineStyle)控制线条样式
  81. width: 3,
  82. color: `#fff`,
  83. shadowColor: `#fff`, // 默认透明
  84. shadowBlur: 10,
  85. },
  86. },
  87. pointer: {
  88. // 分隔线
  89. shadowColor: `#fff`, // 默认透明
  90. shadowBlur: 5,
  91. },
  92. title: {
  93. textStyle: {
  94. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  95. fontWeight: `bolder`,
  96. fontSize: 20,
  97. fontStyle: `italic`,
  98. color: `#fff`,
  99. shadowColor: `#fff`, // 默认透明
  100. shadowBlur: 10,
  101. },
  102. },
  103. detail: {
  104. // backgroundColor: 'rgba(30,144,255,0.8)',
  105. // borderWidth: 1,
  106. // borderColor: '#fff',
  107. // shadowColor: '#fff', //默认透明
  108. // shadowBlur: 5,
  109. offsetCenter: [0, `50%`], // x, y,单位px
  110. textStyle: {
  111. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  112. fontWeight: `bolder`,
  113. fontSize: 25,
  114. color: `#fff`,
  115. },
  116. },
  117. data: [
  118. {
  119. value: 40,
  120. name: `km/h`,
  121. },
  122. ],
  123. },
  124. ],
  125. }
  126. myChart.setOption(this.option, true)
  127. window.addEventListener(`resize`, () => {
  128. myChart.resize()
  129. })
  130. this.timer = setInterval(() => {
  131. this.option.series[0].data[0].value =
  132. (Math.random() * 100).toFixed(2) - 0
  133. myChart.setOption(this.option, true)
  134. }, 2000)
  135. },
  136. },
  137. beforeDestroy() {
  138. clearInterval(this.timer)
  139. },
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .sn-container {
  144. left: 512px;
  145. top: 2838px;
  146. width: 432px;
  147. height: 400px;
  148. .chartsdom {
  149. width: 100%;
  150. height: 100%;
  151. }
  152. }
  153. </style>