Echarts 固定Y轴刻度标签宽度

25 min read

Echarts 固定Y轴刻度标签宽度的配置文件如下 :

option = {
    title: {
        text: 'Echarts 固定Y轴刻度标签宽度',
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    legend: {
        data: ['刻度标签']
    },
    grid: {
        left: '100',            // 固定左边刻度宽度
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'value',
        boundaryGap: [0, 0.01]
    },
    yAxis: {
        type: 'category',
        data: ['巴西', '印尼', '美国', '印度', '中国', '世界人口(万)'],
        axisLabel:{
            inside:true,        // 标签刻度朝内
            margin:0,           // 清除默认间距
            padding:[0,10,0,0], // 右边内边距10
            textStyle:{
                align:'right'   // 文字右对齐
            }
        }
    },
    series: [
        {
            name: '刻度标签',
            type: 'bar',
            data: [18203, 23489, 29034, 104970, 131744, 630230]
        },
      
    ]
};


image-20220918102253274