index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <!-- 支架压力柱状图 -->
  3. <div class="main">
  4. <div ref="bar" style="height: 170px; width: 300px"></div>
  5. <div style="display: flex;flex-flow: column;">
  6. <div class="botton1">
  7. <span class="name">486 /万吨</span>
  8. <span class="value">今年产量</span>
  9. </div>
  10. <div class="botton2">
  11. <span class="name">495 /万吨</span>
  12. <span class="value">计划产量</span>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. name: "Bars",
  20. data() {
  21. return {
  22. myChart: null,
  23. xData: [],
  24. yData: [],
  25. };
  26. },
  27. mounted() {
  28. const option = {
  29. title: {
  30. text: "煤炭产量",
  31. // 标题内边距 上下边距 左右边距titl
  32. padding: [10, 0, 0, 160],
  33. textStyle: {
  34. color: "white",
  35. fontSize: 16,
  36. },
  37. },
  38. tooltip: {
  39. // show: false,
  40. trigger: "axis",
  41. axisPointer: {
  42. type: "shadow",
  43. },
  44. formatter: (params) => {
  45. let round = "<span style=\"display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:#4693EC;\"></span>";
  46. return round + "产量:" + params[0].data + "万吨";
  47. // if (params[0].data > 39) {
  48. // return params[0].marker + "压力过高:" + params[0].data;
  49. // } else if (params[0].data < 26) {
  50. // return params[0].marker + "压力过低:" + params[0].data;
  51. // } else {
  52. // return params[0].marker + "压力正常:" + params[0].data;
  53. // }
  54. },
  55. },
  56. color: ["#FF6666", "#99CC66", "#FFFF66"],
  57. legend: {
  58. show: false,
  59. orient: "horizontal",
  60. left: "right",
  61. padding: [25, 20],
  62. icon: "rect",
  63. textStyle: {
  64. color: "#fff",
  65. },
  66. data: ["压力超限", "压力正常", "压力过低"],
  67. },
  68. grid: {
  69. top: "22%",
  70. left: "3%",
  71. right: "4%",
  72. bottom: "3%",
  73. containLabel: true,
  74. },
  75. xAxis: [
  76. {
  77. type: "category",
  78. axisLabel: {
  79. color: "#fff",
  80. interval: 0,
  81. fontSize: 9,
  82. },
  83. axisLine: {
  84. show: true,
  85. },
  86. data: [
  87. "1月",
  88. "2月",
  89. "3月",
  90. "4月",
  91. "5月",
  92. "6月",
  93. "7月",
  94. "8月",
  95. "9月",
  96. "10月",
  97. "11月",
  98. "12月",
  99. ],
  100. },
  101. ],
  102. yAxis: [
  103. {
  104. type: "value",
  105. name: "万吨",
  106. axisLabel: {
  107. color: "#fff",
  108. // fontSize: 11,
  109. },
  110. nameTextStyle: {
  111. color: "white",
  112. padding: [0, 0, 0, -30],
  113. },
  114. min: 0,
  115. max: 100,
  116. splitLine: {
  117. show: false,
  118. lineStyle: {
  119. type: "dotted",
  120. color: "#fff",
  121. },
  122. },
  123. },
  124. ],
  125. series: [
  126. {
  127. name: "数据",
  128. type: "bar",
  129. barWidth: 12,
  130. itemStyle: {
  131. normal: {
  132. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  133. {
  134. offset: 0,
  135. color: "#00FFE3",
  136. },
  137. {
  138. offset: 1,
  139. color: "#4693EC",
  140. },
  141. ]),
  142. },
  143. },
  144. // barWidth: "10",
  145. barCategoryGap: "5%",
  146. data: [70, 80, 80, 80, 80, 80, 90, 75, 95, 72, 73, 82],
  147. },
  148. // {
  149. // //这两组数据用来模拟markLine线段开关,data可以为空
  150. // name: "压力超限",
  151. // type: "line",
  152. // markLine: {
  153. // data: [
  154. // {
  155. // name: "压力超限",
  156. // yAxis: "64",
  157. // itemStyle: {
  158. // normal: {
  159. // show: true,
  160. // color: "#FF6666",
  161. // },
  162. // },
  163. // },
  164. // ],
  165. // },
  166. // },
  167. // {
  168. // //这两组数据用来模拟markLine线段开关,data可以为空
  169. // name: "压力正常",
  170. // type: "line",
  171. // markLine: {
  172. // data: [
  173. // {
  174. // name: "压力正常",
  175. // yAxis: "24",
  176. // itemStyle: {
  177. // normal: {
  178. // show: true,
  179. // color: "#FFFF66",
  180. // },
  181. // },
  182. // },
  183. // ],
  184. // },
  185. // },
  186. // {
  187. // name: "压力过低",
  188. // type: "line",
  189. // itemStyle: {
  190. // normal: {
  191. // color: "#FFFF66",
  192. // },
  193. // },
  194. // },
  195. ],
  196. };
  197. this.myChart = this.$echarts.init(this.$refs.bar);
  198. // 获取数据
  199. this.myChart.setOption(option);
  200. },
  201. };
  202. </script>
  203. <style scoped lang="less">
  204. .main {
  205. display: flex;
  206. }
  207. .botton1 {
  208. margin-top: 20px;
  209. }
  210. .botton2 {
  211. margin-top: 20px;
  212. }
  213. .name {
  214. color: #4adefe;
  215. font-size: 20px;
  216. display: block;
  217. }
  218. .value {
  219. display: block;
  220. color: white;
  221. text-align: center;
  222. }
  223. </style>