鍍金池/ 問答/數(shù)據(jù)分析&挖掘  HTML5  HTML/ echarts柱狀圖如何中間對(duì)齊而不是底部對(duì)齊?

echarts柱狀圖如何中間對(duì)齊而不是底部對(duì)齊?

我看到大部分柱狀圖插件都是底部對(duì)齊,如何中間對(duì)齊
也不一定非要使用echarts插件做柱狀圖,
就是我我如何才能達(dá)到這種中間對(duì)齊的柱狀圖效果?

圖片描述

回答
編輯回答
網(wǎng)妓

echarts中可以寫個(gè)輔助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: '深圳月最低生活費(fèi)組成(單位:元)',
        subtext: 'From ExcelHome',
        sublink: 'http://e.weibo.com/1341556070/AjQH99che'
    },
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐標(biāo)軸指示器,坐標(biāo)軸觸發(fā)有效
            type : 'shadow'        // 默認(rèn)為直線,可選為:'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 : ['總費(fèi)用','房租','水電費(fèi)','交通費(fèi)','伙食費(fèi)','日用品數(shù)']
    },
    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: '生活費(fèi)',
            type: 'bar',
            stack: '總量',
            label: {
                normal: {
                    show: true,
                    position: 'inside'
                }
            },
            data:data
        }
    ]
};
2018年3月14日 04:10