实现:echarts-柱状图label固定宽度超出隐藏

5 阅读1分钟
  1. 使用v-chart

    <v-chart :option="option" autoresize ref="chartRef"/>
    
  2. option实现

    const option = reactive({
        grid: {
            top: '2%',
            left: 90,
            right: '4%',
            bottom: '3%',
            containLabel: false, // 图表不包含label 如果设置成true,label小于80时则不能撑满,使用rich也不好实现
        },
        yAxis: {
            type: 'category',
            inverse: true,
            data: props.barData?.map(m => m.name),
            axisLabel: {
                interval: 0,
                width: 80,
                overflow: 'truncate', // 超出部分隐藏
            },
            axisTick: {
                show: false // 隐藏刻度线
            },
            splitLine: {
                show: false // 隐藏分隔线
            }
        },
    })