antvis/G2

X轴type是cat,并且值是数值时,绘图计算错误 #3837

xiaoke-1 posted onGitHub

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

复现链接:https://codesandbox.io/s/busy-mendel-91nj7f X轴scale如果是分类类型,值又是数值类型,画出来的柱子往左偏移了一个,tooltip也不准.

这个是util/tooltip.ts的相关代码,这里242行的xValue是索引,originData[xField]是遍历X轴的值,如果X轴的值是数字,就会存在originData[xField]等于xValue,这里为什么会这么比较 微信图片_20220323165730

What does the proposed API look like?

为什么这么设定?如果X轴是分类数据,并且值是数值类型应该怎么实现 另外为啥提交新issues的时候,错误报告里的版本是暂无数据 微信图片_20220323170351

<!-- generated by antv-issue-helper. DO NOT REMOVE -->


微信图片_20220328143356 这个是把官方示例的数据中,数据改成数值类型的,scale改为cat,就会出现的结果

我们现在有个手动组装报表的功能,X轴和Y轴是手动选择的,X轴的数据类型不固定,都是按照scale为cat绘制的,X轴如果选择的是数值类型,并且数值偏小,存在数值和索引相等的情况就会出现诡异的问题

posted by xiaoke-1 about 3 years ago

复现代码:

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

const data = [
  { year: 3, value: 3 },
  { year: 4, value: 4 },
  { year: 5, value: 3.5 },
  { year: 6, value: 5 },
  { year: 7, value: 4.9 },
];
const chart = new Chart({
  container: 'container',
  autoFit: true,
  height: 500,
});

chart.data(data);
chart.scale({
  year: {
    range: [0, 1],
    type: 'cat',
  },
  value: {
    min: 0,
    nice: true,
  },
});

chart.tooltip({
  showCrosshairs: true, // 展示 Tooltip 辅助线
  shared: true,
});

chart.line().position('year*value').label('value');
chart.point().position('year*value');

chart.render();
posted by hustcc almost 3 years ago

先还是手动在外面将 year 转成字符串吧,当前的 PR 修复的方式可能存在一些问题。另外,这个问题在 G2 5.0 中不存在。

posted by hustcc almost 2 years ago

Fund this Issue

$0.00
Funded

Pull requests