lineChartMainPageA.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div
  3. class="linechart"
  4. :id="id"
  5. style="width: calc(100vw - 240px); min-width: 1125px; height: calc(48vh - 165px)"
  6. ></div>
  7. </template>
  8. <script>
  9. import echarts from "echarts";
  10. import { mapState } from "vuex";
  11. export default {
  12. name: "lineChartMainPageA", // 首页-折线图
  13. props: {
  14. id: {
  15. default: "lineChartMainPageA",
  16. type: String,
  17. },
  18. dataList: {
  19. default: function () {
  20. return [];
  21. },
  22. type: Array,
  23. },
  24. },
  25. data() {
  26. return {
  27. tipData: [], //线数据
  28. showData: [], //展示数据
  29. charts: "",
  30. };
  31. },
  32. watch: {
  33. dataList(val) {
  34. if (val.length > 0) {
  35. this.initStateList();
  36. }
  37. },
  38. },
  39. computed: {
  40. ...mapState(["themeColor"]),
  41. },
  42. methods: {
  43. initStateList() {
  44. let xData = [];
  45. let yData = [];
  46. for (let index = 0; index < this.dataList.length; index++) {
  47. const element = this.dataList[index];
  48. xData.push(element.toDate.slice(5));
  49. yData.push(element.num);
  50. }
  51. let option = {
  52. title: {
  53. text: "暂无数据",
  54. show: this.dataList.length === 0,
  55. left: "center",
  56. top: "center",
  57. },
  58. tooltip: {
  59. //提示框,可以在全局也可以在
  60. trigger: "item", //提示框的样式
  61. formatter: "{b}: {c}",
  62. color: "#000", //提示框的背景色
  63. textStyle: {
  64. //提示的字体样式
  65. color: "#ffffff",
  66. },
  67. confine: true,
  68. },
  69. xAxis: {
  70. type: "category",
  71. boundaryGap: false,
  72. // data: [
  73. // "星期一",
  74. // "星期二",
  75. // "星期三",
  76. // "星期四",
  77. // "星期五",
  78. // "星期六",
  79. // "星期日",
  80. // ],
  81. // data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  82. data: xData,
  83. },
  84. yAxis: {
  85. minInterval: 1,
  86. },
  87. series: [
  88. {
  89. // data: [60, 72, 48, 63, 39, 99, 81],
  90. data: yData,
  91. type: "line",
  92. smooth: true,
  93. symbol: "circle",
  94. symbolSize: 6,
  95. lineStyle: {
  96. normal: {
  97. width: 1.5,
  98. color: this.themeColor,
  99. },
  100. },
  101. areaStyle: {
  102. color: new echarts.graphic.LinearGradient(
  103. 0,
  104. 0,
  105. 0,
  106. 1,
  107. [
  108. {
  109. offset: 0,
  110. color: "rgba(51, 151, 255, 0.42)",
  111. },
  112. {
  113. offset: 1,
  114. color: "rgba(170, 197, 255, 0.12)",
  115. },
  116. ]
  117. ),
  118. // color: "#aac5ff",
  119. },
  120. itemStyle: {
  121. normal: {
  122. // 拐点上显示数值
  123. // label: {
  124. // show: true,
  125. // },
  126. // borderColor: this.themeColor, // 拐点边框颜色
  127. color: this.themeColor,
  128. lineStyle: {
  129. // width: 3, // 设置线宽
  130. // type: "dotted", //'dotted'虚线 'solid'实线
  131. // normal: {
  132. // color: "#000",
  133. // },
  134. },
  135. },
  136. },
  137. },
  138. ],
  139. grid: {
  140. top: "10%",
  141. left: "20px",
  142. right: "20px",
  143. bottom: "10%",
  144. containLabel: true,
  145. },
  146. };
  147. this.charts.setOption(option);
  148. },
  149. },
  150. mounted() {
  151. this.charts = this.$echarts.init(document.getElementById(this.id));
  152. this.initStateList();
  153. this.$nextTick(() => {
  154. window.addEventListener("resize", () => {
  155. this.charts.resize();
  156. });
  157. });
  158. },
  159. destroyed() {
  160. // console.log("destroyed");
  161. this.charts.dispose();
  162. },
  163. };
  164. </script>
  165. <style lang='less' scoped>
  166. .linechart {
  167. margin: 0 auto;
  168. overflow: hidden;
  169. }
  170. </style>