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

5.x版本条形图y轴显示双刻度 #6602

Open
2 of 10 tasks
ustcfury opened this issue Feb 13, 2025 · 2 comments
Open
2 of 10 tasks

5.x版本条形图y轴显示双刻度 #6602

ustcfury opened this issue Feb 13, 2025 · 2 comments
Labels
waiting for author Further information is requested from the author

Comments

@ustcfury
Copy link

Describe the bug / 问题描述

5.x版本条形图y轴是否可以显示双刻度,例如左侧显示刻度值,右侧展示刻度百分比?

Image

Reproduction link / 复现链接

无复现

Steps to Reproduce the Bug or Issue / 重现步骤

No response

Version / 版本

🆕 5.x

OS / 操作系统

  • macOS
  • Windows
  • Linux
  • Others / 其他

Browser / 浏览器

  • Chrome
  • Edge
  • Firefox
  • Safari (Limited support / 有限支持)
  • IE (Nonsupport / 不支持)
  • Others / 其他
@ustcfury ustcfury added the waiting for maintainer Triage or intervention needed from a maintainer label Feb 13, 2025
Copy link

在 G2 5.x 版本中,您可以通过自定义 y 轴的刻度来实现显示双刻度的效果,例如左侧显示刻度值,右侧展示刻度百分比。虽然官方文档中没有直接提到双刻度的实现,但您可以通过以下方法进行自定义:

  1. 自定义刻度:您可以使用 scale 方法来自定义 y 轴的刻度。例如,您可以定义一个自定义的 tickMethod 来生成所需的刻度值。

    chart
      .interval()
      // ...
      .scale('y', {
        type: 'linear',
        domain: [0, 100],
        tickMethod: () => [0, 20, 40, 60, 80, 100] // 自定义刻度
      });
  2. 使用多轴:如果需要在同一图表中显示不同的刻度单位(如值和百分比),可以考虑使用多轴图表。通过在图表中添加多个 y 轴来实现不同的刻度显示。

    具体实现可能需要结合自定义的刻度和多轴配置来达到您想要的效果。

如果您需要更详细的实现步骤或示例代码,请告诉我,我会尽力帮助您。

🪧 Tips For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.

@hustcc
Copy link
Member

hustcc commented Feb 13, 2025

可以参考官网双轴图的案例代码。

@interstellarmt interstellarmt added Website waiting for author Further information is requested from the author and removed waiting for maintainer Triage or intervention needed from a maintainer Website labels Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for author Further information is requested from the author
Projects
None yet
Development

No branches or pull requests

3 participants