LineChart.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!-- 圆饼图 -->
  2. <template>
  3. <div :id="id" :class="className" :style="{height, width}" />
  4. </template>
  5. <script setup lang="ts">
  6. import * as echarts from "echarts";
  7. const props = defineProps({
  8. id: {
  9. type: String,
  10. default: "lineChart",
  11. required: true,
  12. },
  13. className: {
  14. type: String,
  15. default: "chart",
  16. },
  17. width: {
  18. type: String,
  19. default: "400px",
  20. },
  21. height: {
  22. type: String,
  23. default: "300px",
  24. },
  25. title: {
  26. type: String,
  27. default: "",
  28. },
  29. //[20, 30, 50, 78, 53, 47, 60,30, 50, 78, 53, 47, 60,30, 50, 78, 53, 47, 60]
  30. data: {
  31. type: Array,
  32. default: [] as Array<number>,
  33. },
  34. });
  35. /**
  36. * 配置项
  37. */
  38. const options = {
  39. grid: {
  40. x: "8%",
  41. y: "8%",
  42. x2: "12%",
  43. y2: "12%",
  44. },
  45. xAxis: {
  46. type: "category",
  47. data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
  48. boundaryGap: true,
  49. axisLabel: {
  50. color: "#09132e",
  51. interval: (value: number, index: number) => {
  52. return index % 4 == 0;
  53. },
  54. },
  55. axisLine: {
  56. show: true,
  57. lineStyle: {
  58. color: "#aaaaaa",
  59. },
  60. },
  61. axisTick: {
  62. show: true,
  63. alignWithLabel: true,
  64. },
  65. },
  66. yAxis: {
  67. type: "value",
  68. max: 100,
  69. interval: 10,
  70. axisLabel: {
  71. color: "#09132e",
  72. },
  73. axisLine: {
  74. show: true,
  75. lineStyle: {
  76. color: "#aaaaaa",
  77. },
  78. },
  79. splitNumber: 10,
  80. axisTick: {
  81. show: true,
  82. alignWithLabel: true,
  83. },
  84. },
  85. series: [
  86. {
  87. data: props.data,
  88. type: "line",
  89. symbol: "circle",
  90. symbolSize: 10,
  91. lineStyle: {
  92. normal: {
  93. color: {
  94. type: "linear",
  95. x: 0,
  96. y: 0,
  97. x2: 0,
  98. y2: 1,
  99. colorStops: [
  100. {
  101. offset: 0,
  102. color: "#ffd223",
  103. },
  104. {
  105. offset: 1,
  106. color: "#9685fb",
  107. },
  108. ],
  109. },
  110. },
  111. },
  112. },
  113. ],
  114. visualMap: {
  115. type: "continuous",
  116. min: 0,
  117. max: 100,
  118. text: ["HIGH", "LOW"],
  119. realtime: false,
  120. calculable: false,
  121. color: ["#ffd223", "#9685fb"],
  122. itemWidth: 30,
  123. right: "5%",
  124. bottom: "8%",
  125. },
  126. };
  127. onMounted(() => {
  128. // 图表初始化
  129. const chart = echarts.init(document.getElementById(<string>props.id) as HTMLDivElement);
  130. chart.setOption(options);
  131. // 大小自适应
  132. window.addEventListener("resize", () => {
  133. chart.resize();
  134. });
  135. });
  136. </script>