antvis/G2

数据量较大的柱状图加上滚动条后,如何调整柱宽使符合预期 #5442

KuduroJS posted onGitHub

示例: image

按照预期,此时柱宽应是和数据量无关的,不会因数据量变大而变小,滚动显示即可。 类似的问题还有折线图等。

请问怎么解决呢。

示例代码:

/**
 * A recreation of this demo: https://observablehq.com/@d3/line-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/551d80c6-a6be-4f3c-a82a-abd739e12977.csv',
  })
  .encode('x', 'date')
  .encode('y', 'close')
  .scrollbar('x');

chart.render();

需要外置进行计算,根据 x 的数据量,以及画布大小,计算出 scrollbar 的 ratio。

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/551d80c6-a6be-4f3c-a82a-abd739e12977.csv',
  })
  .encode('x', 'date')
  .encode('y', 'close')
  .scrollbar('x', { ratio: 0.05 }); // 👈🏻这里

文档见这里:https://g2.antv.antgroup.com/spec/interaction/scrollbar-filter

posted by hustcc over 1 year ago

Fund this Issue

$0.00
Funded

Pull requests