ny
23 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
 
import { onMounted, ref } from 'vue';
 
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
 
const props = defineProps({
  data: {
    default: () => [],
    type: Array as any,
  },
});
 
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
 
function init() {
  if (!props.data.length) return;
  const xAxisData = props.data[0].category || [];
  const series: any = [];
  for (let i = 0; i < props.data.length; i++) {
    const item = {
      name: props.data[i].name,
      data: props.data[i].data,
      type: 'bar',
      barMaxWidth: 80,
    };
    series.push(item);
  }
  const options: any = {
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          width: 1,
          color: '#019680',
        },
      },
    },
    grid: { left: '10px', right: '10px', top: '50px', bottom: 0, containLabel: true },
    xAxis: {
      name: '时间',
      type: 'category',
      axisLine: {
        symbol: ['none', 'arrow'],
      },
      data: xAxisData,
    },
    yAxis: {
      type: 'value',
      splitNumber: 4,
      axisLine: {
        symbol: ['none', 'arrow'],
      },
      name: '数量',
    },
    legend: {
      show: true,
      right: 0,
    },
    series,
  };
  renderEcharts(options);
}
 
onMounted(() => {
  init();
});
</script>
 
<template>
  <EchartsUI ref="chartRef" height="400px" />
</template>