antvis/G2

雷达图网格线数量控制,tickCount属性设置与表现时常不一致 #3580

machen8812 posted onGitHub

  • I have searched the issues of this repository and believe that this is not a duplicate.

Edit on CodeSandbox

Steps to reproduce

修改scale下的tickCount属性,tickCount =3或者tickCount =4,图形上都只有2个网格线。tickCount=5时,展示4个网格线

Environment Info
g2 4.1.24
System windows10
Browser Google Chrome 92.0.4515.131(正式版本) (64 位)

<!-- generated by antv-issue-helper. DO NOT REMOVE -->


tickCount 只是一个提示,并不是最终的生成的 ticks 的数量。因为需要保证 tick 的可读性(尽量是 1,2,5,10 的倍数),所以会调整 tick 的数量。如何希望 ticks 的数量和 tickCount 一致,可以自定义 tickMethod 方法。(如下)

chart.scale("score", {
  min: 0,
  // max: 80,
  nice: true,
  // 网格隐藏
  tickCount: 5,
  tickMethod: ({min, max, tickCount}) => {
    const step = (max - min) / tickCount;
    return new Array(tickCount).fill(0).map((_,  i) => min + i * step);
  }
});
posted by pearmini over 3 years ago

Fund this Issue

$0.00
Funded

Pull requests