【跪求大佬】echart横向柱状图,如何让它距离y坐标轴有点距离?

是不是入错行了 2021-05-24 05:57:29
希望达到这种效果

但是现在是这种效果

这个柱子直接贴在y轴了,百度了好久,在官网也找不到相关api,求大佬帮助一下,小弟感激不尽,来日必请你去曹县恰饭
【下面这段代码可以复制,随便在echarts官网找个实例复制进去,就是我现在那种效果,希望会的大佬在上面修改一下

option = {
title: {
text: '全市评估报表',
left: 'center'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},

grid: {
top: '15%',
left: '1%',
right: '4%',
bottom: '2%',
containLabel: true
},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01],
},
yAxis: {
type: 'category',
data: ['2020年1月', '2020年2月', '2020年3月', '2020年4月', '2020年5月', '2020年6月', '2020年7月', '2020年8月'],

},
series: [
{

type: 'bar',
data: [91, 55, 46, 87, 99,100,56,30],
itemStyle: {
emphasis: {
barBorderRadius: 30
},
normal: {
color: new echarts.graphic.LinearGradient(
0, 0.3, 0.8, 1,
[
{offset: 0, color: '#83bff6'},
{offset: 0.5, color: '#40daaf'},
{offset: 1, color: '#03c158'}
]
),
//柱形图圆角,初始化效果
barBorderRadius:[50, 50, 50, 50],
label: {
show: true,//是否展示
position: 'right',
textStyle: {
fontWeight:'bolder',
fontSize : '12',
color: 'black',
}
}
}
},

}
]
};
...全文
8448 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
helloTech_2021 2023-11-14
  • 打赏
  • 举报
回复

在xAxis中的boundaryGap属性,设置为false代表是零刻度开始,设置为true代表离零刻度间隔一段距离

xAxis: {
type: 'category',
boundaryGap: true,
data: ['周一','周二','周三','周四','周五','周六','周日']
},

calvin陈 2021-12-13
  • 打赏
  • 举报
回复

利用双Y轴功能,一个Y左侧偏移,原始Y进行隐藏就可以了

gqkmiss 2021-05-25
  • 打赏
  • 举报
回复
gqkmiss 2021-05-25
  • 打赏
  • 举报
回复
变相的操作,加一个总量,覆盖在下面

option = {
     title: {
        text: '全市评估报表',
        left: 'center'
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {            // 坐标轴指示器,坐标轴触发有效
            type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
        },
        formatter: function (params) {
            var tar = params[1];
            return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
        }
    },
    
    
    grid: {
        top: '15%',
        left: '1%',
        right: '4%',
        bottom: '2%',
        containLabel: true
    },
    xAxis: {
        type: 'value',
        boundaryGap: [0, 0.01],
    },
    yAxis: {
        type: 'category',
        data: ['2020年1月', '2020年2月', '2020年3月', '2020年4月', '2020年5月', '2020年6月', '2020年7月', '2020年8月'],
      
    },
    series: [
        {

            type: 'bar',
            stack: '总量',
            itemStyle: {
                barBorderColor: 'rgba(0,0,0,0)',
                color: 'rgba(0,0,0,0)'
            },
            emphasis: {
                itemStyle: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                }
            },
            data: [5, 5, 5, 5, 5, 5, 5, 5]
        },
        {
            stack: '总量',
            type: 'bar',
            data: [91, 55, 46, 87, 99,100,56,30],
            itemStyle: {
                 emphasis: {
                            barBorderRadius: 30
                        },
                        normal: {
                            color: new echarts.graphic.LinearGradient(
                                0, 0.3, 0.8, 1,
                    [
                        {offset: 0, color: '#83bff6'},
                        {offset: 0.5, color: '#40daaf'},
                        {offset: 1, color: '#03c158'}
                    ]
                ),
                            //柱形图圆角,初始化效果
                            barBorderRadius:[50, 50, 50, 50],
                            label: {
                                show: true,//是否展示
                                position: 'right',
                                textStyle: {
                                    fontWeight:'bolder',
                                    fontSize : '12',
                                    color: 'black', 
                                }
                            }
                        }
            },
            
        }
    ] 
};
  • 打赏
  • 举报
回复
引用 3 楼 gqkmiss 的回复:
需要的是这种情况吗?
是的。怎么弄的,大佬
gqkmiss 2021-05-25
  • 打赏
  • 举报
回复
需要的是这种情况吗?
  • 打赏
  • 举报
回复
公司美工把图画好了,我还想直接把案例cv过来呢
  • 打赏
  • 举报
回复
谢谢老哥,只不过项目经理说就我之前那种,你这种方法之前也看到过,你分有了
泡泡鱼_ 2021-05-24
  • 打赏
  • 举报
回复 1
……这是柱状图,人家的原点就是紧挨着Y轴线的呀。你左边要是空出那一些,那空出来的代表什么呢?难道你觉得那样“好看”些???? 为什么要纠结于实现这种与原功能相背的?
angulaer 2021-12-08
  • 举报
回复 6
@泡泡鱼_ 公司没有ui吧?
是老年程序员 2022-10-10
  • 举报
回复 1
@angulaer 说得好,ui设计的东西,几乎都是反人类的
m0_65530641 2023-09-07
  • 举报
回复 1
@泡泡鱼_ 说得好,派你去和我公司ui对线

87,992

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧