Echarts 堆叠柱状图

17 min read
let colotArr=['#77A7F5','#58BFBF','#D99260','#FFCC52']
option = {
    tooltip: {
        trigger: 'axis',
        axisPointer: {            // 坐标轴指示器,坐标轴触发有效
            type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
        }
    },
    backgroundColor:'#021434',
    color:colotArr,
    legend: {
        icon: 'circle',
        itemGap: 15,
        itemWidth: 10, // 设置宽度
        itemHeight: 10,
        top:'0',
        right:'30',
        textStyle: {
            color: '#fff'
        },
        data: ['离心机供能', '地缘热泵供能', '储能罐供能', '地源热泵供能']
    },
    grid: {
        left: '4%',
        right: '4%',
        bottom: '3%',
        top:'10%',
        containLabel: true
    },
    xAxis: {
        type: 'category',
        axisLine: {
            lineStyle: {
                color: '#273860'
            }
        },
        axisTick: {
            show: false
        },
        axisLabel: { //坐标轴刻度标签的相关设置。
            interval: 0, //设置为 1,表示『隔一个标签显示一个标签』
            margin: 15,
            textStyle: {
                color: '#ACCFFF',
                fontStyle: 'normal',
                fontSize: 12,
            }
        },
        data: Array.from(Array(24).keys())
    },
    yAxis: {
        type: 'value',
        axisLabel: { //坐标轴刻度标签的相关设置。
            interval: 0, //设置为 1,表示『隔一个标签显示一个标签』
            textStyle: {
                color: '#ACCFFF',
                fontStyle: 'normal',
                fontFamily: '微软雅黑',
                fontSize: 12,
            }
        },
        axisTick: {
            show: false
        },
        axisLine: {
            lineStyle: {
                color: '#273860'
            }
        },
        splitLine: {
            lineStyle: {
                color: '#273860'
            },
        },
    },
    series: [
        {
            name: '离心机供能',
            type: 'bar',
            stack: '总量',
            barWidth:'30%',
            label: {
                show: true,
                position: 'insideRight'
            },
            data: Array.from({length: 24}, () => Math.floor(Math.random() * 400)),
        },
        {
            name: '地缘热泵供能',
            type: 'bar',
            stack: '总量',
            barWidth:'30%',
            label: {
                show: true,
                position: 'insideRight'
            },
            data:Array.from({length: 24}, () => Math.floor(Math.random() * 400)),
        },
        {
            name: '储能罐供能',
            type: 'bar',
            barWidth:'30%',
            stack: '总量',
            label: {
                show: true,
                position: 'insideRight'
            },
            data: Array.from({length: 24}, () => Math.floor(Math.random() * 400)),
        },
        {
            name: '地源热泵供能',
            type: 'bar',
            barWidth:'30%',
            stack: '总量',
            label: {
                show: true,
                position: 'insideRight'
            },
            data: Array.from({length: 24}, () => Math.floor(Math.random() * 400)),
        },
      
    ]
};

image-20220427175851323