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

折线图按Y轴降序排序 #6544

Closed
LUUUAN opened this issue Dec 9, 2024 · 2 comments · Fixed by #6621
Closed

折线图按Y轴降序排序 #6544

LUUUAN opened this issue Dec 9, 2024 · 2 comments · Fixed by #6621
Labels
bug 🐛 Something isn't working OSCP AntV Open Source Contribution Plan

Comments

@LUUUAN
Copy link

LUUUAN commented Dec 9, 2024

问题描述

使用transform({ type: 'sortX', by: 'y', reverse: true}) 对折线图排序,会导致线条错乱

重现链接

https://codesandbox.io/p/sandbox/nervous-joliot-hg59ty

重现步骤

No response

预期行为

期望能够实现折线图按Y轴降序排序

平台

  • 操作系统: [macOS,]
  • 网页浏览器: [Google Chrome]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response

@hustcc hustcc added the OSCP AntV Open Source Contribution Plan label Dec 9, 2024
@pearmini
Copy link
Member

pearmini commented Dec 9, 2024

复现代码如下:原因应该是 sortX 当 x 通道是 ordinal 数据的时候,只对 x scale 的 domain 进行了排序,而不是对数据整体进行排序。

image
import { Chart } from "@antv/g2";

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

// Apply academy theme.
chart.theme({ type: "academy" });

chart
  .line()
  .data({
    type: "fetch",
    value:
      "https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv",
    format: "csv",
  })
  .transform({ type: "groupX", reducer: "sum" })
  .encode("x", "state")
  .encode("y", "population")
  .encode("series", () => "b")
  .transform({ type: "sortX", by: "y" });

chart.render();

但是如下设置也不行 .transform({ type: "sortX", by: "y", ordinal: false });,这个问题可能需要看看?@hustcc

image

@interstellarmt interstellarmt added bug 🐛 Something isn't working help wanted labels Feb 10, 2025
@BQXBQX
Copy link
Contributor

BQXBQX commented Mar 1, 2025

使用 .transform({ type: "sortX", by: "y", ordinal: false }) 时, by 并没有起到作用,sort 是只是简单的根据 channel 进行了排序,而且 domain 也没有进行排序。

Image

代码修改成如下后,正常渲染

Image Image

BQXBQX added a commit to BQXBQX/G2 that referenced this issue Mar 1, 2025
This commit fixes issue antvis#6544 by:
- Implementing proper domain-based sorting in the sortQuantitative transform
- Adding support for slicing sorted domains
- Creating a test case that demonstrates the fix
- Enhancing the sort transform to handle sorting by a different channel than the one being displayed
hustcc pushed a commit that referenced this issue Mar 6, 2025
* fix(chart): resolve issue #6544 with line chart sorting

This commit fixes issue #6544 by:
- Implementing proper domain-based sorting in the sortQuantitative transform
- Adding support for slicing sorted domains
- Creating a test case that demonstrates the fix
- Enhancing the sort transform to handle sorting by a different channel than the one being displayed

* refactor(transform): unify sorting logic

* refactor(transform): simplify Sort implementation by inlining unifiedSort logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working OSCP AntV Open Source Contribution Plan
Projects
Development

Successfully merging a pull request may close this issue.

5 participants