关于如何设置echart图例(legend)的位置

本文详细介绍了Echart中图例(legend)的各种设置方法,包括位置、背景颜色、item间隔、宽度高度、文字颜色、边框颜色及内边距等属性的调整技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于如何设置echart图例(legend)的位置
列举几种常见的排列方式
在这里插入图片描述
实现代码
legend: {
orient: ‘vertical’,
left: ‘center’,
bottom:‘bottom’,
data: [‘直接访问’,‘邮件营销’,‘联盟广告’,‘视频广告’,‘搜索引擎’]
}
在这里插入图片描述
实现代码
legend: {
orient: ‘vertical’,
left: ‘right’,
top:‘bottom’,
data: [‘直接访问’,‘邮件营销’,‘联盟广告’,‘视频广告’,‘搜索引擎’]
}

其余针对legend的常用命令
改变背景颜色( backgroundColor)
在这里插入图片描述
实现代码
legend: {
orient: ‘vertical’,
left: ‘right’,
top:‘bottom’,
backgroundColor: ‘rgba(100,0,100,0.5)’,
// backgroundColor: ‘rgba(0,0,0,0.2)’,
data: [‘直接访问’,‘邮件营销’,‘联盟广告’,‘视频广告’,‘搜索引擎’]
}
改变各个item之间的间隔(itemGap),单位px,默认为10,横向布局时为水平间隔,纵向布局时为纵向间隔
在这里插入图片描述
实现代码
legend: {
orient: ‘vertical’,
left: ‘right’,
top:‘bottom’,
backgroundColor: ‘rgba(0,0,0,0.2)’,
itemGap: 1,
data: [‘直接访问’,‘邮件营销’,‘联盟广告’,‘视频广告’,‘搜索引擎’]
}

改变图例宽度高度(itemWidth,itemHeight)
在这里插入图片描述
实现代码
legend: {
orient: ‘vertical’,
left:‘center’,
bottom:‘bottom’,
backgroundColor: ‘rgba(0,0,0,0.2)’,
itemWidth: 50,
itemHeight: 20,
data: [‘直接访问’,‘邮件营销’,‘联盟广告’,‘视频广告’,‘搜索引擎’]
}

改变图例文字颜色(textStyle)
在这里插入图片描述
实现代码
legend: {
orient: ‘vertical’,
left:‘center’,
bottom:‘bottom’,
backgroundColor: ‘rgba(0,0,0,0.2)’,
textStyle: {
color: ‘#0f0’
// color:‘rgb(250,235,0)’
},
data: [‘直接访问’,‘邮件营销’,‘联盟广告’,‘视频广告’,‘搜索引擎’]
}

改变图例边框颜色.图例边框线宽(默认无边框,单位px)(borderColor,borderWidth)
在这里插入图片描述
实现代码
legend: {
orient: ‘vertical’,
left:‘center’,
bottom:‘bottom’,
backgroundColor: ‘rgba(0,0,0,0.2)’,
borderColor: ‘#0f0’,
borderWidth: 2,
data: [‘直接访问’,‘邮件营销’,‘联盟广告’,‘视频广告’,‘搜索引擎’]
}
改变图例内边距,单位px,默认各方向内边距为5,接受数组分别设定上右下左边距,同css(padding)
在这里插入图片描述
实现代码
legend: {
orient: ‘vertical’,
left:‘center’,
bottom:‘bottom’,
backgroundColor: ‘rgba(0,0,0,0.2)’,
padding: 1,
data: [‘直接访问’,‘邮件营销’,‘联盟广告’,‘视频广告’,‘搜索引擎’]
}

总结:个人觉得这篇文章比较全面 https://blog.csdn.net/she_lover/article/details/51448967

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值