Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(interval): log scale with zero value #5226

Merged
merged 1 commit into from
Jun 25, 2023
Merged

Conversation

pearmini
Copy link
Member

Log Scale

close: #5185

添加一个 example 解决当 Log Scale 不能映射 0 值的问题。

解释

经过排查,上面 issue 中的问题不是 bug。其中 y1 为 [0, 0, 0, ..., 0],而 log 比例尺无法映射 0。如果真的希望使用 log 比例尺,可以修改 y1 为接近 0 的值,同时设置 labelFormatter。

import { Chart } from '@antv/g2';

const EPSILON = 1e-6;

const chart = new Chart({
  container: 'container',
  theme: 'classic',
  padding: 'auto',
  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')
  .encode('y1', EPSILON) // Log scale cant' map zero, set a value close to zero.
  .scale('y', { type: 'log' })
  .axis('y', { labelFormatter: (d) => (d === EPSILON ? 0 : d) });

chart.render();

@hustcc hustcc merged commit 36bf1fa into v5 Jun 25, 2023
3 checks passed
@hustcc hustcc deleted the docs/interval-log-zero branch June 25, 2023 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

log scale 设置 domainMin 无效
2 participants