alarmingChart.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div ref="alarmingChart" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. import api from "../../../../api/site/Event_alarm";
  7. import { ElMessage } from "element-plus";
  8. export default {
  9. props: {},
  10. data() {
  11. return {};
  12. },
  13. mounted() {},
  14. beforeUnmount() {
  15. window.removeEventListener("resize", this.chart);
  16. },
  17. watch: {
  18. /**
  19. * @监听vuex存储值变化 用于调用api
  20. */
  21. "$store.state.siteId": {
  22. immediate: true, // 首次加载的时候执行函数
  23. deep: true, // 深入观察,监听数组值,对象属性值的变化
  24. handler: function () {
  25. this.trendIco_api();
  26. },
  27. },
  28. },
  29. methods: {
  30. /**
  31. * @事件告警统计api请求
  32. */
  33. trendIco_api() {
  34. var _this = this;
  35. this.$store.commit("getTimeAll");
  36. this.$store.commit("TimeAll_function", this.$store.state.fh_defaultTime);
  37. var time = this.$store.state.Time_Data;
  38. api
  39. .trendIco({
  40. siteId: _this.$store.state.siteId,
  41. startTime: time[0],
  42. endTime: time[1],
  43. queryType: null,
  44. })
  45. .then((requset) => {
  46. if (requset.status === "SUCCESS") {
  47. var data = requset.data[0];
  48. _this.initChart(data.list, data.listDate);
  49. } else {
  50. ElMessage.success({
  51. message: requset.msg,
  52. type: "success",
  53. });
  54. }
  55. });
  56. },
  57. //次数分布折线图
  58. initChart(data, dataTime) {
  59. var chart = echarts.init(this.$refs.alarmingChart);
  60. var option;
  61. option = {
  62. // backgroundColor:'#323a5e',
  63. tooltip: {
  64. trigger: "axis",
  65. axisPointer: {
  66. // 坐标轴指示器,坐标轴触发有效
  67. type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
  68. },
  69. },
  70. grid: {
  71. left: "0%",
  72. right: "0%",
  73. bottom: "0%",
  74. top: "16%",
  75. containLabel: true,
  76. },
  77. xAxis: {
  78. type: "category",
  79. data: dataTime,
  80. axisLine: {
  81. lineStyle: {
  82. color: "rgba(0,0,0,0.1)",
  83. },
  84. },
  85. axisTick: {
  86. show: false,
  87. },
  88. axisLabel: {
  89. textStyle: {
  90. color: "#fff",
  91. fontFamily: "Microsoft YaHei",
  92. },
  93. },
  94. },
  95. yAxis: {
  96. minInterval:1,//将刻度的最小间距设置为1
  97. name: "(条)",
  98. nameTextStyle: {
  99. color: "#fff",
  100. },
  101. type: "value",
  102. // max: "800",
  103. axisLine: {
  104. show: false,
  105. lineStyle: {
  106. color: "white",
  107. },
  108. },
  109. splitLine: {
  110. show: true,
  111. lineStyle: {
  112. color: "rgba(255,255,255,0.1)",
  113. },
  114. },
  115. axisLabel: {},
  116. },
  117. series: [
  118. {
  119. name: "昨日",
  120. type: "bar",
  121. barWidth: "20%",
  122. barGap: "0%",
  123. itemStyle: {
  124. normal: {
  125. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  126. {
  127. offset: 0,
  128. color: "#00A7FD",
  129. },
  130. {
  131. offset: 1,
  132. color: "#00A7FD",
  133. },
  134. ]),
  135. },
  136. },
  137. data: data,
  138. },
  139. ],
  140. };
  141. chart.setOption(option, true);
  142. window.addEventListener("resize", () => {
  143. chart.resize();
  144. });
  145. this.chart = chart;
  146. },
  147. },
  148. };
  149. </script>