ECharts 柱状图 配置项总结

柱状图在这里插入图片描述

<!DOCTYPE html>
<html style="height: 100%">

<head>
    <meta charset="utf-8">
</head>

<body style="height: 100%; margin: 0">
    <div id="container" style="width: 50%;height: 50%"></div>

    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts-nightly@5.1.2-dev.20210512/dist/echarts.min.js"></script>

    <script type="text/javascript">
        var dom = document.getElementById("container");
        var myChart = echarts.init(dom);
        var app = {};

        var option;

        var arr1 = [20, 32, 10, 32, 32, 32, 32];
        var arr2 = [50, 20, 50, 60, 60, 60, 50];
        var arr3 = [620, 732, 701, 734, 1090, 1130, 1120];

        // y轴最大值-根据数据变化而变化
        var test1 = Math.max.apply(null, arr1) //数组中取得最大值
        var test2 = Math.max.apply(null, arr2)
        var test3 = Math.max.apply(null, arr3)
        var max1 = test1 + test2
        var max2 = test3
        
        option = {
            color: ['#61a0a8', '#c23531', '#91c7ae'],
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器,坐标轴触发有效
                    type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                }
            },
            legend: {
                data: ['当日已支付', '当日总量', '当月总量'],  //标题
                x: '270px',   //自定义位置
                y: '0px',
                textStyle: {
                    fontSize: 14, //字体大小
                    color: 'red'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: 'pink'
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: 'pink'
                        }
                    },
                    axisTick: {
                        show: false
                    }

                }
            ],
            yAxis: [
                {
                    name: '当日',
                    type: 'value',
                    max: max1,
                    min: 0,
                    nameTextStyle: {
                        color: "#65ABE7",
                        fontSize: 12
                    },
                    axisLine: {
                        show: true,
                        lineStyle: {
                            color: 'pink'
                        },
                    },
                    axisTick: {
                        show: false,
                    },
                    splitLine: {     //网格线
                        "show": false
                    },
                    axisLabel: {
                        textStyle: {
                            color: 'pink'
                        }
                    }
                },
                {
                    type: 'value',
                    scale: true,
                    name: '当月',
                    max: max2,
                    min: 0,
                    nameTextStyle: {
                        color: "#65ABE7",
                        fontSize: 12
                    },
                    boundaryGap: [0.2, 0.2],   //坐标轴两端空白,数值为百分比
                    axisTick: {
                        show: false,
                    },
                    splitLine: {     //网格线
                        "show": false
                    },
                    axisLine: {
                        show: true,  //轴线是否显示
                        lineStyle: {  //轴线样式
                            color: 'pink'
                        }
                    },
                    axisLabel: {
                        textStyle: {
                            color: 'pink'
                        }
                    }
                }
            ],
            series: [
                {
                    name: '当日已支付',
                    type: 'bar',
                    barGap: 0,
                    stack: '1',
                    emphasis: {
                        focus: 'series'
                    },
                    label: {
                        show: true,
                        //    position: 'top',
                            color:'red',
                    },
                    data: arr1
                },
                {
                    name: '当日总量',
                    type: 'bar',
                    stack: '1',
                    emphasis: {
                        focus: 'series'
                    },
                    label: {
                        position: 'top',
                        color: 'yellow',
                        show: true
                    },
                    data: arr2
                },
                {
                    name: '当月总量',
                    type: 'bar',
                    yAxisIndex: 1,
                    // barWidth: 5,
                    emphasis: {
                        focus: 'series'
                    },
                    label: {
                        show: true,
                        position: 'top',
                        color: 'yellow'
                    },
                    data: arr3
                }
            ]
        };
        if (option && typeof option === 'object') {
            myChart.setOption(option);
        }

    </script>
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值