waterLevel.vue 3.4 KB

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