当前位置:网站首页>echart:横向柱状图的类目文字位置调整
echart:横向柱状图的类目文字位置调整
2022-06-28 19:28:00 【@我不认识你】
前言
echarts的横向柱状图也是比较常见的,但是类目文字基本上都是在左侧,比如:
但是你永远可以相信你的项目经理或产品经理会给你找麻烦,比如给客户看的ui图,文字是上面的:
遇到一些好说话的客户还好可以协商,但是有些客户。。。 最后苦逼的就是我们开发的。
正文
能实现该效果吗?虽然一直没有见过类似的,但是还真能实现。
代码
option = {
xAxis: {
type: 'value'
},
yAxis: {
type: 'category',
axisLabel: {
show: false },
data: ['abc', 'abcdefgh']
},
series: [
{
name: 'Cost',
type: 'bar',
label: {
show: true,
formatter: '{b}',
position: 'left',
align: 'left',
offset: [10, -20]
},
barWidth: 20,
data: [10, 20]
}
]
};
效果图
注意点:
1、在yAxis里必须添加 axisLabel: { show: false }, ,不然会出现两个类目,比如:

2、series 里 label 的属性配置(关键)
label: {
show: true,
formatter: '{b}',
position: 'left',
align: 'left',
offset: [10, -20]
},
show: true,显示类目文字position: 'left',设置成left,一开始方向错了设置成了top,浪费了不少时间align: 'left',设置文字对齐方式,必须设置,不然会出现文字位置不一致的问题offset: [10, -20]偏移量,第一个是横向偏移;第二个是纵向偏移。第一个自己根据实际情况,第二个建议绝对值等于barWidth(柱的宽度)
边栏推荐
猜你喜欢

智能计算系统3 Plugin 集成开发的demo

秋招经验分享 | 银行笔面试该怎么准备

try except 添加辅助新列

Fontawesome icon for color gradient

new String(“hello“)之后,到底创建了几个对象?

The white paper on the panorama of the digital economy and the digitalization of consumer finance were released

Idea merge other branches into dev branch

视差js特效js轮播图插件

Hands on Teaching of servlet use (1)

shell读取Json文件的值
随机推荐
Win11底部状态栏如何换成黑色?Win11底部状态栏换黑色的方法
How to remove dataframe field column names
几行代码就能实现复杂的 Excel 导入导出,这个工具类真心强大!
How to learn JS through w3school / how to use the JS reference manual of w3school
Matlab 2D or 3D triangulation
C#连接数据库完成增删改查操作
事实/论断/断言/结论/断定/判定
SQL interview question: find the maximum number of consecutive login days
Build halo blog in arm version rk3399
《数字经济全景白皮书》消费金融数字化篇 重磅发布
math_证明常用等价无穷小&案例&代换
How many objects are created after new string ("hello")?
How does win11 slim down the system disk? Slimming method of win11 system disk
PCL 计算平面三角形外接圆的圆心和半径
F (x) construct the equation, calculate the partial derivative by gradient descent, determine the partial derivative adjustment by loss function, and deal with nonlinear problems by activation functio
论文3 VScode&texlive&SumatraPDF打造完美书写论文工具
请问下flinkcdc用flinksql提交的话只能一个表提交一个任务吗?那有几千张表的时候还能这么
智能计算系统2 bangc算子开发的demo (CPU和MLU270的异构编程流程)
Intelligent computing system 1 environment construction
Full MySQL solution ubuntu/win10