antvis/G2

设置domainMin后显示超过下界 #5454

KuduroJS posted onGitHub

image

预期应该是不超过X轴

请问这是正常吗,或是使用错误?

示例代码:

/**
 * A recreation of this demo: https://observablehq.com/@d3/bar-chart
 */
import { Chart } from '@antv/g2';

const chart = new Chart({
  container: 'container',
  theme: 'classic',
  autoFit: true,
});

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
  })
  .encode('x', 'letter')
  .encode('y', 'frequency')
  .axis('y', { labelFormatter: '.0%' })
  .scale("y", {
    domainMin: 0.1
  });

chart.render();

柱形图其实 y 是有两个,一个是底部,一个是顶部,只是默认底部为 0 而已。如果期望设置底部为 0.1 开始,那可以这样写。

  .encode('y', [0.1, 'frequency'])
  .scale('y', { domainMin: 0.1 })
posted by hustcc over 1 year ago

这个是合理的,因为条的下边界的数据是 0。除了上诉方法之外,还可以:

const chart = new Chart({
  clip: true // 隐藏超出绘制区域的地方
})

或者

interval().scale('y', { 
  domainMin: 0.1 
  clamp: true
});
posted by pearmini over 1 year ago

Fund this Issue

$0.00
Funded

Pull requests