multiple-line-chart.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div class="chart" 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. legend: {
  21. show: true,
  22. data: chartData.value.map((t) => {
  23. return t.title;
  24. }),
  25. right: 56,
  26. icon: "circle",
  27. itemWidth: 6,
  28. inactiveColor: '#606769',
  29. textStyle: {
  30. color: '#B3BDC0',
  31. fontSize: 12,
  32. },
  33. },
  34. xAxis: [
  35. {
  36. type: "category",
  37. boundaryGap: false,
  38. axisLabel: {
  39. // interval: 60,
  40. showMinLabel: true,
  41. showMaxLabel: true,
  42. formatter: "{value}",
  43. fontSize: 14,
  44. textStyle: {
  45. color: '#606769',
  46. },
  47. },
  48. axisLine: {
  49. show: false,
  50. },
  51. data: chartData.value[0].value.map(items => {
  52. return items.text;
  53. }),
  54. },
  55. ],
  56. yAxis: {
  57. type: "value",
  58. axisLabel: {
  59. formatter: "{value}",
  60. fontSize: 14,
  61. },
  62. axisLine: {
  63. show: false,
  64. },
  65. splitLine: {
  66. show: true,
  67. lineStyle: {
  68. color: '#606769',
  69. type: "dashed",
  70. },
  71. },
  72. },
  73. dataZoom: [
  74. {
  75. show: false,
  76. type: 'inside',
  77. start: 0,
  78. end: 100
  79. },
  80. ],
  81. series: [{
  82. name: chartData.value[0].title,
  83. smooth: true,
  84. showSymbol: false,
  85. data: chartData.value[0].value.map(items => {
  86. return items.value;
  87. }),
  88. type: 'line',
  89. lineStyle: {
  90. normal: {
  91. color: 'rgba(75, 85, 174, 1)',
  92. width: 1,
  93. },
  94. },
  95. },
  96. {
  97. name: chartData.value[1].title,
  98. smooth: true,
  99. showSymbol: false,
  100. data: chartData.value[1].value.map(items => {
  101. return items.value;
  102. }),
  103. type: 'line',
  104. lineStyle: {
  105. normal: {
  106. color: 'rgba(05, 187, 76, 1)',
  107. width: 1,
  108. },
  109. },
  110. }]
  111. };
  112. option && myChart.setOption(option);
  113. },
  114. },
  115. };
  116. </script>
  117. <style lang="less">
  118. .chart {
  119. width: 1050px;
  120. height: 40vh;
  121. }
  122. </style>