Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

柱状图x 轴 encode的编码对应值过长,会导致encode x轴 编码不显示 #6001

Closed
hxz1993 opened this issue Jan 3, 2024 · 5 comments

Comments

@hxz1993
Copy link

hxz1993 commented Jan 3, 2024

问题描述

在绘制柱状图时,x 轴的文本过长,导致 genre 字符不显示了
image

重现链接

No response

重现步骤

import { Chart } from '@antv/g2';

const chart = new Chart({ container: 'container' });

chart
.interval()
.data([
{ genre: 'Sports哈哈哈哈哈哈你你你版本他他哼哼唧唧哦', sold: 0 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
])
.encode('x', 'genre')
.encode('y', 'sold')
.encode('color', 'genre')
// .style('minHeight', 50);

chart.title({
title:'主标题',
subtitle:'副标题',
style:{
titleFontSize:32,
titleFill:'red'
}
})

chart.render();

预期行为

x 轴文本过长正常被截取,但是x 轴的genre 字符 能正常显示

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response

@pearmini
Copy link
Member

pearmini commented Jan 3, 2024

这里可以通过 labelFormatter 解决哈:

chart.interval().label({
  labelFormatter: d => d.length > 5 ? d.slice(0, 5) + "...." : d
})

@hxz1993
Copy link
Author

hxz1993 commented Jan 3, 2024

labelFormatter 不能用,这个是处理label,我这边是x 坐标显示内容

@pearmini
Copy link
Member

pearmini commented Jan 3, 2024

哦,写错了:

chart.interval().axis('x', {
  labelFormatter: d => d.length > 5 ? d.slice(0, 5) + "..." : d
})

@hxz1993
Copy link
Author

hxz1993 commented Jan 3, 2024

我不能指定说超过多少个字符截取,因为我们这边区域高度不是固定的,需要自适应,

@pearmini
Copy link
Member

pearmini commented Jan 4, 2024

那你可以设置 paddingBottom 会取消旋转,自动隐藏:

const chart = new Chart({
  paddingBottom: 50
})

@hustcc hustcc closed this as completed Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants