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

g2 v5版本折线图(line) 设置shape为smooth(曲线)后,对于中间出现连续0的场景画线异常 #5541

Closed
bfyq opened this issue Sep 14, 2023 · 7 comments · Fixed by #5751
Milestone

Comments

@bfyq
Copy link

bfyq commented Sep 14, 2023

问题描述:
我实现了一个简单的折线图,用平滑的曲线画线,但是在中间遇到连续的0(先升后降再升场景)时,发现v5下的版本存在问题,想求助下是我v5配置的问题,还是v5就存在这样的问题(sorry, 文档阅读了半天,没找到什么有用信息,感觉v5文档看api稍微难理解)
这是之前v4版本下的样式截图:
image
这是我在v5版本下的样式截图
image

  • G2 Version: g5 v5.1.2
  • Platform: web, g2官网示例编辑
  • Mini Showcase(like screenshots): 画线异常
  • CodePen Link:
import { Chart } from '@antv/g2';

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

chart
  .line()
  .data([
    {
      'date': '2-1',
      'close': 1,
    },
    {
      'date': '2-2',
      'close': 10,
    },
    {
      'date': '2-3',
      'close': 0,
    },
    {
      'date': '2-4',
      'close': 0,
    },
    {
      'date': '2-5',
      'close': 12,
    },
  ])
  .encode('x', 'date')
  .encode('y', 'close')
  .encode('connect', false)
  .style('shape', 'smooth');

chart.render();
@pearmini
Copy link
Member

目前曲线是用 d3-line 绘制的,传递参数的能力缺失。

@bfyq
Copy link
Author

bfyq commented Sep 14, 2023

谢谢大佬们

@bfyq
Copy link
Author

bfyq commented Sep 14, 2023

目前曲线是用 d3-line 绘制的,传递参数的能力缺失。

问下,什么版本会优化这个呀

@pearmini
Copy link
Member

看了一下,这里有两种处理方法,第一种:

// 设置 alpha 参数,效果会好很多
chart.line().style('shape', 'smooth').style('alpha', 1);

第二种,使用 d3 的 curveMonotoneX 曲线生成器:

import { curveMonotoneX } from 'd3-shape';

chart.line().style('shape', 'smooth').style('curve', () => curveMonotoneX)

@sqlyr
Copy link

sqlyr commented Oct 17, 2023

image
image
请问这属于同质问题嘛

@pearmini
Copy link
Member

对,应该是一类问题

@sqlyr
Copy link

sqlyr commented Oct 17, 2023

我试了下上面的方案,对我现在成图都不太友好,大改多久能修复呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

4 participants