antvis/G2

数据都是负数的时候对比例尺设置最大值失效 #4412

xiekailian posted onGitHub

代码如下:

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

const data = [
  { type: '未知', value: -10, percent: 0.02 },
  { type: '17 岁以下', value: -20, percent: 0.02 },
  { type: '18-24 岁', value: -30, percent: 0.2 },
  { type: '25-29 岁', value: -40, percent: 0.24 },
];

const chart = new Chart({
  container: 'container',
  autoFit: true,
  height: 500,
  padding: [50, 20, 50, 20],
});
chart.data(data);
chart.scale('value', {
  alias: '销售额(万)',
});

chart.axis('type', {
  tickLine: {
    alignTick: false,
  },
});

chart.tooltip({
  showMarkers: false,
});
chart.interval().position('type*value');
chart.interaction('element-active');

chart.scale('value', {
  max: -50
});

chart.render();

设置比例尺的最大值为 -50,预期情况是,什么都不显示,因为所有值都比 -50 大,就像这样: <img width="598" alt="image" src="https://user-images.githubusercontent.com/18750815/205858638-48b66988-af94-420b-8543-c28fa621adea.png"> 然而官网复现出来,是这样: <img width="832" alt="image" src="https://user-images.githubusercontent.com/18750815/205858886-4c7a9dd8-c966-43fd-b31a-1a67622cd3ef.png"> 看起来只隐藏了第一个数据,其他的没反应。


max min 都会和具体的数据进行比较之后再做处理。如果强制按照用户设置的来处理,那就用这个:

chart.scale('value', {
  maxLimit: -50, // 👈🏻
  // minLimit: 10,
});
posted by hustcc over 2 years ago

感谢,确实有效

posted by xiekailian over 2 years ago

Fund this Issue

$0.00
Funded

Pull requests