antvis/G2





The issue has been closed
SortX 支持对连续通道排序 #4356
pearmini posted onGitHub
SortX
目前的 Sort 只针对离散数据,通过对 scale.domain
去排序达到对数据排序的效果。同时应该增加对连续数据排序的能力。
import { Chart } from '@antv/g2';
import { sort } from 'd3-array';
const data = [/** */];
const chart = new Chart({
container: 'container',
autoFit: true,
});
chart
.line()
.data(data)
.encode('x', (d) => d)
.transform({ type: 'binX', y: 'count' })
.transform({ type: SortX })
chart.render();
// 简单的实现方式如下
function SortX() {
return (I, mark) => {
const { encode } = mark;
const { x } = encode;
const X = x.value;
const sortedX = sort(I, (i) => X[i]);
return [sortedX, mark];
};
}