AnalysisLine.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div ref="chartRef" :style="{ height, width }"></div>
  3. </template>
  4. <script lang="ts">
  5. import { defineComponent, onMounted, ref, Ref } from 'vue';
  6. import { useECharts } from '/@/hooks/web/useECharts';
  7. import { basicProps } from './props';
  8. export default defineComponent({
  9. name: 'AnalysisLine',
  10. props: basicProps,
  11. setup() {
  12. const chartRef = ref<HTMLDivElement | null>(null);
  13. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  14. onMounted(() => {
  15. setOptions({
  16. // title: {
  17. // text: '产品成交额',
  18. // },
  19. tooltip: {
  20. trigger: 'axis',
  21. padding: 3,
  22. backgroundColor: 'rgba(0, 0, 0, .6)',
  23. borderColor: '#777',
  24. borderWidth: 1,
  25. },
  26. legend: {
  27. icon: 'rect',
  28. itemWidth: 15,
  29. itemHeight: 4,
  30. left: 80,
  31. top: 0,
  32. orient: 'horizontal',
  33. data: ['产品一', '产品二'],
  34. },
  35. grid: {
  36. left: '3%',
  37. right: '4%',
  38. bottom: '3%',
  39. containLabel: true,
  40. },
  41. xAxis: {
  42. type: 'category',
  43. boundaryGap: false,
  44. axisTick: {
  45. inside: true, // 刻度朝内
  46. },
  47. data: [
  48. '一月',
  49. '二月',
  50. '三月',
  51. '四月',
  52. '五月',
  53. '六月',
  54. '七月',
  55. '八月',
  56. '九月',
  57. '十月',
  58. '十一月',
  59. '十二月',
  60. ],
  61. },
  62. yAxis: {
  63. type: 'value',
  64. axisTick: {
  65. inside: true, // 刻度朝内
  66. },
  67. },
  68. series: [
  69. {
  70. name: '产品一',
  71. type: 'line',
  72. itemStyle: {
  73. normal: {
  74. color: '#5B8FF9',
  75. },
  76. },
  77. // areaStyle: {},
  78. data: [330, 132, 101, 134, 90, 230, 210, 150, 232, 234, 230, 400],
  79. animationDuration: 4000,
  80. },
  81. {
  82. name: '产品二',
  83. type: 'line',
  84. itemStyle: {
  85. normal: {
  86. color: '#55D187',
  87. },
  88. },
  89. data: [220, 182, 191, 234, 290, 330, 310, 330, 232, 201, 330, 190],
  90. animationDuration: 4000,
  91. },
  92. ],
  93. });
  94. });
  95. return { chartRef };
  96. },
  97. });
  98. </script>