zhangxiao
2024-08-20 e47b788ff5f5c699c682999c95da17eb284ca21d
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
import { EChartsOption } from "echarts";
import { isArray, merge } from "lodash-es";
 
const echartsHelper = {
    option(params: Record<string, any>, merging?: boolean) {
        if (merging === false) {
            return merge(
                {
                    backgroundColor: "rgba(0,0,0,0)"
                },
                params
            );
        }
        const defaultOpt: EChartsOption = {
            backgroundColor: "rgba(0,0,0,0)",
            tooltip: {
                trigger: "axis",
                axisPointer: {
                    type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
                    label: {
                        backgroundColor: "#6a7985"
                    }
                }
            },
            legend: {
                icon: "rect",
                itemWidth: 8,
                itemHeight: 8,
                right: "10px"
            },
            grid: {
                top: 80,
                left: 20,
                right: 20,
                bottom: 20,
                containLabel: true
            }
        };
        const xAxisParmas = {
            axisLabel: {}
        };
        if (isArray(params?.xAxis)) {
            params?.xAxis?.forEach((item) => {
                merge(item, xAxisParmas);
            });
        } else {
            merge(params, {
                xAxis: xAxisParmas
            });
        }
        return merge(defaultOpt, params);
    }
};
export default echartsHelper;