antvis/G2

[Bug]: 折线图x轴为日期时,scale的domain失败 #6700

583849487 posted onGitHub

Describe the bug / 问题描述

用g2最新版5.2.0中遇到的,后端给的data结构为如下:{"time": "03-14 14:00", "type": "PM10", "value": 56 }……,有个需求是将x轴从3.1到3.31,但后端给的只有三月份部分时间数据,所以看了文档使用scale的domain方法去实现,但是在操作过程中没有成功,请大佬帮看下问题。感谢

No response

Steps to Reproduce the Bug or Issue / 重现步骤

如果不用scale部分代码,正常是这样

Version / 版本

Please select / 请选择

OS / 操作系统

  • macOS
  • Windows
  • Linux
  • Others / 其他

Browser / 浏览器

  • Chrome
  • Edge
  • Firefox
  • Safari (Limited support / 有限支持)
  • IE (Nonsupport / 不支持)
  • Others / 其他

两个方法:

  1. x 轴的 encode 转成 Date 类型即可。

就会默认扩充数据,如果不设置为 Date 类型,就会当做是分类数据,有什么就显示什么。

encode: {
  x: d => new Date(d. time)
}
  1. x 轴继续使用字符串,作为分类数据

然后手动在数据中补齐数据没这个应该不是你想要的。

posted by hustcc about 1 month ago

⚠️ This issue has been automatically closed due to inactivity.

  • If the issue is still relevant and important to you, feel free to:
    1. Reopen with additional information
    2. Create a new issue with updated context
    3. Reference any related issues or discussions

We close inactive issues to keep our backlog manageable and focused on active issues.

Your contribution makes our project better! 🌟


⚠️ 由于长期无活动,此 issue 已被自动关闭。

  • 如果这个问题对您来说仍然重要,您可以:
    1. 重新打开并提供补充信息
    2. 创建一个新的 issue 并更新相关背景
    3. 关联相关的 issue 或讨论

为了更好地维护项目,我们需要定期清理不活跃的问题。

感谢您为开源添砖加瓦!🌟

posted by github-actions[bot] 25 days ago

Fund this Issue

$0.00
Funded

Pull requests