multiple-line-chart.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="charts" id="showEchart"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. export default {
  7. name: "multiple-line-chart",
  8. componentName: "multiple-line-chart",
  9. data() {
  10. return {
  11. id: "",
  12. chart: null,
  13. };
  14. },
  15. methods: {
  16. initChart(chartData) {
  17. let chartDom = document.getElementById("showEchart");
  18. let myChart = echarts.init(chartDom, "#ffffff");
  19. let option = {
  20. tooltip: {
  21. trigger: 'axis'
  22. },
  23. legend: {
  24. show: true,
  25. data: chartData.value.map((t) => {
  26. return t.title;
  27. }),
  28. right: 56,
  29. icon: "circle",
  30. itemWidth: 6,
  31. inactiveColor: "#606769",
  32. textStyle: {
  33. color: "#B3BDC0",
  34. fontSize: 12,
  35. },
  36. },
  37. xAxis: [
  38. {
  39. type: "category",
  40. boundaryGap: false,
  41. axisLabel: {
  42. // interval: 60,
  43. showMinLabel: true,
  44. showMaxLabel: true,
  45. formatter: "{value}",
  46. fontSize: 14,
  47. textStyle: {
  48. color: "#606769",
  49. },
  50. },
  51. axisLine: {
  52. show: false,
  53. },
  54. data: chartData.value[0].value.map((items) => {
  55. return items.text;
  56. }),
  57. },
  58. ],
  59. yAxis: {
  60. type: "value",
  61. axisLabel: {
  62. formatter: "{value}",
  63. fontSize: 14,
  64. },
  65. axisLine: {
  66. show: false,
  67. },
  68. splitLine: {
  69. show: true,
  70. lineStyle: {
  71. color: "#606769",
  72. type: "dashed",
  73. },
  74. },
  75. },
  76. dataZoom: [
  77. {
  78. show: false,
  79. type: "inside",
  80. start: 0,
  81. end: 100,
  82. },
  83. ],
  84. series: [
  85. {
  86. name: chartData.value[0].title,
  87. smooth: true,
  88. showSymbol: false,
  89. data: chartData.value[0].value.map((items) => {
  90. return items.value;
  91. }),
  92. type: "line",
  93. lineStyle: {
  94. normal: {
  95. color: "rgba(75, 85, 174, 1)",
  96. width: 1,
  97. },
  98. },
  99. },
  100. {
  101. name: chartData.value[1].title,
  102. smooth: true,
  103. showSymbol: false,
  104. data: chartData.value[1].value.map((items) => {
  105. return items.value;
  106. }),
  107. type: "line",
  108. lineStyle: {
  109. normal: {
  110. color: "rgba(05, 187, 76, 1)",
  111. width: 1,
  112. },
  113. },
  114. },
  115. ],
  116. };
  117. option && myChart.setOption(option);
  118. },
  119. },
  120. };
  121. </script>
  122. <style lang="less" scoped>
  123. .charts {
  124. width: 1050px;
  125. height: 40vh;
  126. }
  127. </style>