Skip to content

y通道type=log报错 #5181

Answered by pearmini
xyr550 asked this question in Q&A
Jun 9, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

经过排查,这个不是 bug。上面例子中的 y1 为 [0, 0, 0, ..., 0],而 log 比例尺无法映射 0。如果真的希望使用 log 比例尺,可以修改 y1 为接近 0 的值,如下:

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

const epsilon = 1e-6;

const chart = new Chart({ container: 'container' });

chart.options({
  type: 'interval',
  theme: 'classic',
  padding: 'auto',
  data: {
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/fb9db6b7-23a5-4c23-bbef-c54a55fee580.csv',
  },
  encode: { x: 'letter', y: 'frequency', y1: epsilon },
  scale: { y: { type: 'log', tickCount: -1 } },
  axis: { y: { labelFormatter: (d) => (d === epsilon ? 0 : d) } },
});

chart.render();

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@pearmini
Comment options

Answer selected by pearmini
@pearmini
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants