Line.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div ref="chartRef" :style="{ height, width }"></div>
  3. </template>
  4. <script lang="ts">
  5. import { defineComponent, PropType, ref, Ref, onMounted } from 'vue';
  6. import { useECharts } from '/@/hooks/web/useECharts';
  7. import { getLineData } from './data';
  8. export default defineComponent({
  9. props: {
  10. width: {
  11. type: String as PropType<string>,
  12. default: '100%',
  13. },
  14. height: {
  15. type: String as PropType<string>,
  16. default: 'calc(100vh - 78px)',
  17. },
  18. },
  19. setup() {
  20. const chartRef = ref<HTMLDivElement | null>(null);
  21. const { setOptions, echarts } = useECharts(chartRef as Ref<HTMLDivElement>);
  22. const { barData, lineData, category } = getLineData;
  23. onMounted(() => {
  24. setOptions({
  25. backgroundColor: '#0f375f',
  26. tooltip: {
  27. trigger: 'axis',
  28. axisPointer: {
  29. type: 'shadow',
  30. label: {
  31. show: true,
  32. backgroundColor: '#333',
  33. },
  34. },
  35. },
  36. legend: {
  37. data: ['line', 'bar'],
  38. textStyle: {
  39. color: '#ccc',
  40. },
  41. },
  42. xAxis: {
  43. data: category,
  44. axisLine: {
  45. lineStyle: {
  46. color: '#ccc',
  47. },
  48. },
  49. },
  50. yAxis: {
  51. splitLine: { show: false },
  52. axisLine: {
  53. lineStyle: {
  54. color: '#ccc',
  55. },
  56. },
  57. },
  58. series: [
  59. {
  60. name: 'line',
  61. type: 'line',
  62. smooth: true,
  63. showAllSymbol: 'auto',
  64. symbol: 'emptyCircle',
  65. symbolSize: 15,
  66. data: lineData,
  67. },
  68. {
  69. name: 'bar',
  70. type: 'bar',
  71. barWidth: 10,
  72. itemStyle: {
  73. borderRadius: 5,
  74. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  75. { offset: 0, color: '#14c8d4' },
  76. { offset: 1, color: '#43eec6' },
  77. ]),
  78. },
  79. data: barData,
  80. },
  81. {
  82. name: 'line',
  83. type: 'bar',
  84. barGap: '-100%',
  85. barWidth: 10,
  86. itemStyle: {
  87. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  88. { offset: 0, color: 'rgba(20,200,212,0.5)' },
  89. { offset: 0.2, color: 'rgba(20,200,212,0.2)' },
  90. { offset: 1, color: 'rgba(20,200,212,0)' },
  91. ]),
  92. },
  93. z: -12,
  94. data: lineData,
  95. },
  96. {
  97. name: 'dotted',
  98. type: 'pictorialBar',
  99. symbol: 'rect',
  100. itemStyle: {
  101. color: '#0f375f',
  102. },
  103. symbolRepeat: true,
  104. symbolSize: [12, 4],
  105. symbolMargin: 1,
  106. z: -10,
  107. data: lineData,
  108. },
  109. ],
  110. });
  111. });
  112. return { chartRef };
  113. },
  114. });
  115. </script>