waterLevel.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <!-- 支架压力柱状图 -->
  3. <div ref="bar" style="height: 150px; width: 500px; margin-left: 40px"></div>
  4. </template>
  5. <script>
  6. /**
  7. * 工作区水害图
  8. * @module waterLevel
  9. */
  10. export default {
  11. name: "Bars",
  12. data() {
  13. return {
  14. myChart: null,
  15. option: {
  16. title: {
  17. text: "探孔水位/m",
  18. left: 100,
  19. top: 10,
  20. textStyle: {
  21. fontWeight: "normal", //标题颜色
  22. color: "#4ADEFE",
  23. },
  24. },
  25. tooltip: {
  26. trigger: "axis",
  27. axisPointer: {
  28. type: "shadow",
  29. },
  30. formatter: (params) => {
  31. if (params[0].data > 64) {
  32. return params[0].marker + "压力过高:" + params[0].data;
  33. } else {
  34. return params[0].marker + "压力正常:" + params[0].data;
  35. }
  36. },
  37. },
  38. color: ["#FF6666", "#99CC66", "#FFFF66"],
  39. grid: {
  40. left: "3%",
  41. right: "4%",
  42. bottom: "3%",
  43. containLabel: true,
  44. },
  45. xAxis: [
  46. {
  47. type: "category",
  48. axisLabel: {
  49. color: "rgb(255,255,255)",
  50. fontSize: 11,
  51. },
  52. axisLine: {
  53. show: true,
  54. // color: ""
  55. },
  56. data: [1, 2],
  57. },
  58. ],
  59. yAxis: [
  60. {
  61. type: "value",
  62. max: 80,
  63. min: 0,
  64. axisLabel: {
  65. color: "#fff",
  66. fontSize: 11,
  67. },
  68. splitLine: {
  69. show: false,
  70. lineStyle: {
  71. type: "dotted",
  72. color: "#fff",
  73. },
  74. },
  75. },
  76. ],
  77. series: [
  78. {
  79. name: "压力过低",
  80. type: "bar",
  81. itemStyle: {
  82. normal: {
  83. color: function (params) {
  84. if (params.data > 64) {
  85. return "#FF6666";
  86. } else {
  87. return "#99CC66";
  88. }
  89. },
  90. label: {
  91. show: true, //开启显示
  92. position: "top", //在上方显示
  93. textStyle: {
  94. //数值样式
  95. color: function (params) {
  96. if (params.data > 64) {
  97. return "#FF6666";
  98. } else {
  99. return "#99CC66";
  100. }
  101. },
  102. fontSize: 15,
  103. },
  104. },
  105. },
  106. },
  107. barWidth: "10",
  108. barCategoryGap: "5%",
  109. data: [50, 55],
  110. },
  111. {
  112. //这两组数据用来模拟markLine线段开关,data可以为空
  113. name: "压力超限",
  114. type: "line",
  115. markLine: {
  116. data: [
  117. {
  118. name: "压力超限",
  119. yAxis: "60",
  120. itemStyle: {
  121. normal: {
  122. show: true,
  123. color: "#FF6666",
  124. },
  125. },
  126. },
  127. ],
  128. },
  129. },
  130. ],
  131. },
  132. };
  133. },
  134. mounted() {
  135. console.log(this.$echarts);
  136. this.myChart = this.$echarts.init(this.$refs.bar);
  137. this.myChart.setOption(this.option);
  138. let interval = setInterval(() => {
  139. let temp = [];
  140. for (let i = 0; i < 2; i++) {
  141. temp.push(this.getRandomNum(0, 80));
  142. }
  143. this.myChart.setOption({
  144. series: [
  145. {
  146. data: temp,
  147. },
  148. ],
  149. });
  150. }, 3000);
  151. this.$once("hook:beforeDestroy", () => {
  152. clearInterval(interval);
  153. });
  154. },
  155. };
  156. </script>
  157. <style></style>