Device_distion.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div
  3. ref="distion"
  4. :class="className"
  5. :style="{ height: height, width: width }"
  6. ></div>
  7. </template>
  8. <script>
  9. import * as echarts from "echarts";
  10. export default {
  11. props: {
  12. defaul_tTime: {
  13. type: Array,
  14. },
  15. className: {
  16. type: String,
  17. default: "chart",
  18. },
  19. width: {
  20. type: String,
  21. default: "100%",
  22. },
  23. height: {
  24. type: String,
  25. default: "400px",
  26. },
  27. perData: {
  28. type: Array,
  29. default: () => [
  30. {
  31. color: "#01ACFF",
  32. name: "摄像头",
  33. value: [39],
  34. // nAmount: 566557.14,
  35. },
  36. ],
  37. },
  38. },
  39. data() {
  40. return {
  41. chart: null,
  42. color_XY: "rgba(0, 244, 253, 0.1)",
  43. msgFormSon: null,
  44. data_time: [
  45. "2021-07-01 00:00:00",
  46. "2021-07-02 00:00:00",
  47. "2021-07-03 00:00:00",
  48. "2021-07-04 00:00:00",
  49. "2021-07-05 00:00:00",
  50. "2021-07-06 00:00:00",
  51. "2021-07-07 00:00:00",
  52. "2021-07-08 00:00:00",
  53. "2021-07-09 00:00:00",
  54. "2021-07-10 00:00:00",
  55. "2021-07-11 00:00:00",
  56. "2021-07-12 00:00:00",
  57. "2021-07-13 00:00:00",
  58. "2021-07-14 00:00:00",
  59. ],
  60. };
  61. },
  62. mounted() {
  63. this.$nextTick(() => {
  64. this.initChart();
  65. console.log(this.defaul_tTime);
  66. });
  67. },
  68. beforeUnmount() {
  69. window.removeEventListener("resize", this.chart);
  70. },
  71. methods: {
  72. //次数分布折线图
  73. initChart() {
  74. var _this = this;
  75. var chart = echarts.init(this.$refs.distion);
  76. var option;
  77. var data = [0, 0, 0, 0, 0, 1, 1,1,1,1,1,1,1,1].map((val, ind) => {
  78. return [_this.data_time[ind], val];
  79. });
  80. option = {
  81. title: [
  82. {
  83. text: "OFF次数分布",
  84. left: "center",
  85. textStyle: {
  86. color: "#fff",
  87. fontSize: 14,
  88. },
  89. },
  90. {
  91. text: `OFF次数:${0}`,
  92. left: "right",
  93. padding: [0, "7", 0, 0],
  94. textStyle: {
  95. color: "#fff",
  96. fontSize: 14,
  97. },
  98. },
  99. ],
  100. tooltip: {
  101. backgroundColor: "rgba(0, 244, 253, 0.1)",
  102. borderColor: "rgba(0, 244, 253, 0.3)",
  103. textStyle: {
  104. color: "#fff",
  105. },
  106. trigger: "axis",
  107. axisPointer: {
  108. type: "line",
  109. },
  110. formatter: function (params) {
  111. // console.log(params);
  112. var res = params[0].data[0];
  113. for (let i in params) {
  114. res += `
  115. <div style="display:flex">
  116. <div style="width:10px;height:10px;background:${
  117. params[i].color
  118. };border-radius: 10px;margin:10px 0;"></div>
  119. <div style="padding:4px 0px 0px 10px;">${
  120. params[i].seriesName
  121. }:</div>
  122. <div style="padding:4px 0px 0px 10px;">${
  123. params[i].data[1]
  124. }</div>
  125. </div>`; //可以在这个方法中做改变
  126. }
  127. return res;
  128. },
  129. },
  130. xAxis: {
  131. type: "time",
  132. boundaryGap: false,
  133. nameTextStyle: {
  134. // 名称样式
  135. fontSize: 12,
  136. color: "#fff",
  137. fontWeight: "bold",
  138. },
  139. axisLabel: {
  140. showMaxLabel: true,
  141. textStyle: {
  142. color: "#fff", //坐标值得具体的颜色
  143. },
  144. formatter: {
  145. year: "{MM}-{dd}\n{yyyy}",
  146. month: `{MM}-{dd}\n{yyyy}`,
  147. day: `{MM}-{dd}\n{yyyy}`,
  148. hour: "{HH}:{mm}\n{MM}-{dd}",
  149. minute: "{HH}:{mm}",
  150. second: "{HH}:{mm}:{ss}",
  151. millisecond: "{hh}:{mm}:{ss} {SSS}",
  152. none: "{yyyy}-{MM}-{dd} {hh}:{mm}:{ss} {SSS}",
  153. },
  154. },
  155. axisLine: {
  156. lineStyle: {
  157. color: this.color_XY,
  158. },
  159. },
  160. },
  161. grid: {
  162. left: "3%",
  163. right: "4%",
  164. bottom: "10%",
  165. containLabel: true,
  166. },
  167. yAxis: {
  168. splitLine: {
  169. lineStyle: {
  170. // 使用深浅的间隔色
  171. color: [this.color_XY],
  172. },
  173. },
  174. type: "value",
  175. // splitNumber: 4,
  176. // min: 4,
  177. max: 4,
  178. axisLabel: {
  179. textStyle: {
  180. color: "#fff", //坐标值得具体的颜色
  181. },
  182. },
  183. },
  184. series: [
  185. {
  186. name: `OFF次数`,
  187. type: "line",
  188. smooth: true,
  189. data: data,
  190. },
  191. ],
  192. };
  193. chart.setOption(option);
  194. window.addEventListener("resize", () => {
  195. chart.resize();
  196. });
  197. this.chart = chart;
  198. },
  199. },
  200. };
  201. </script>