antvis/G2

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

LUUUAN posted onGitHub

问题描述

使用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


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

<img width="683" alt="image" src="https://github.com/user-attachments/assets/174e971e-9036-44db-a111-daf6d0cad336">

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

<img width="670" alt="image" src="https://github.com/user-attachments/assets/4c3a485a-6f04-479a-8115-b93fc9750faa">

posted by pearmini 5 months ago

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

<img width="589" alt="Image" src="https://github.com/user-attachments/assets/92e91947-3a16-405f-a483-1a8989457f31" />

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

<img width="623" alt="Image" src="https://github.com/user-attachments/assets/8bc601cf-19de-4851-bd61-2d02080aec9b" />

<img width="1037" alt="Image" src="https://github.com/user-attachments/assets/42edb85c-044c-4efa-857e-621adfbcff9e" />

posted by BQXBQX about 2 months ago

Fund this Issue

$0.00
Funded

Pull requests