lineChartTaskInfo.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="linechart" :id="id" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. export default {
  6. name: "lineChartTaskInfo",
  7. props: {
  8. id: {
  9. default: "lineChartA",
  10. type: String,
  11. },
  12. xList: {
  13. default: function () {
  14. return [];
  15. },
  16. type: Array,
  17. },
  18. yList: {
  19. default: function () {
  20. return [];
  21. },
  22. type: Array,
  23. },
  24. yUnit: {
  25. default: "",
  26. type: String,
  27. },
  28. },
  29. data() {
  30. return {
  31. tipData: [], //线数据
  32. showData: [], //展示数据
  33. charts: "",
  34. };
  35. },
  36. watch: {
  37. yList(val) {
  38. if (val.length > 0) {
  39. this.initStateList();
  40. }
  41. },
  42. },
  43. methods: {
  44. initStateList() {
  45. let xData = this.xList;
  46. let yData = this.yList;
  47. let option = {
  48. title: {
  49. text: "暂无数据",
  50. show: yData.length === 0,
  51. left: "center",
  52. top: "center",
  53. },
  54. tooltip: {
  55. //提示框,可以在全局也可以在
  56. trigger: "item", //提示框的样式
  57. formatter: "{b}: {c}",
  58. // formatter: function (params) {
  59. // if (params.value == 0) return params.name + " : 0";
  60. // //格式化函数
  61. // return params.name + " : " + params.value.toFixed(4);
  62. // },
  63. color: "#000", //提示框的背景色
  64. textStyle: {
  65. //提示的字体样式
  66. color: "#ffffff",
  67. },
  68. confine: true,
  69. },
  70. xAxis: {
  71. name: "t(s)",
  72. type: "category",
  73. boundaryGap: false,
  74. data: xData,
  75. },
  76. yAxis: {
  77. name: this.yUnit,
  78. },
  79. series: [
  80. {
  81. data: yData,
  82. type: "line",
  83. smooth: true,
  84. symbol: "circle",
  85. symbolSize: 6,
  86. lineStyle: {
  87. normal: {
  88. width: 1.5,
  89. color: "#3397FF",
  90. },
  91. },
  92. itemStyle: {
  93. normal: {
  94. color: "#3397FF",
  95. },
  96. },
  97. },
  98. ],
  99. grid: {
  100. top: "30px",
  101. left: "30px",
  102. right: "40px",
  103. bottom: "10%",
  104. containLabel: true,
  105. },
  106. };
  107. this.charts.setOption(option);
  108. },
  109. },
  110. mounted() {
  111. this.charts = this.$echarts.init(document.getElementById(this.id));
  112. this.initStateList();
  113. this.$nextTick(() => {
  114. window.addEventListener("resize", () => {
  115. this.charts.resize();
  116. });
  117. });
  118. },
  119. destroyed() {
  120. this.charts.dispose();
  121. },
  122. };
  123. </script>
  124. <style lang='less' scoped>
  125. .linechart {
  126. margin: 0 auto;
  127. overflow: hidden;
  128. }
  129. </style>