echarts柱状图如何中间对齐而不是底部对齐?

我看到大部分柱状图插件都是底部对齐,如何中间对齐
也不一定非要使用echarts插件做柱状图,
就是我我如何才能达到这种中间对齐的柱状图效果?

图片描述

阅读 5.7k
1 个回答

echarts中可以写个辅助bar “顶起来”

图片描述

var data = [2900, 1000, 1400, 1200, 300, 230]

function iData (data) {
    let max = Math.max.apply(null,data)
    console.log(max)
    let iData = data.map((item) => {
        return max - item /2
    })
    return iData
}


option = {
    title: {
        text: '深圳月最低生活费组成(单位:元)',
        subtext: 'From ExcelHome',
        sublink: 'http://e.weibo.com/1341556070/AjQH99che'
    },
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器,坐标轴触发有效
            type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
        },
        formatter: function (params) {
            var tar = params[1];
            return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type : 'category',
        splitLine: {show:false},
        data : ['总费用','房租','水电费','交通费','伙食费','日用品数']
    },
    yAxis: {
        type : 'value'
    },
    series: [
        {
            name: '辅助',
            type: 'bar',
            stack:  '总量',
            itemStyle: {
                normal: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                },
                emphasis: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                }
            },
            data: iData(data)
        },
        {
            name: '生活费',
            type: 'bar',
            stack: '总量',
            label: {
                normal: {
                    show: true,
                    position: 'inside'
                }
            },
            data:data
        }
    ]
};
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题