You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vega Lite绘制24小时智能体状态转换图故障求助

解决Vega-Lite 24小时时间轴缩放后可视化损坏的问题

问题根源

你给x轴添加的scale.domain用了{"hours": 0}这种时间对象格式,但在指定timeUnit: "hours"后,Vega-Lite会把原始时间字段转换成0到23之间的小时数值(比如23:59对应23.98左右)。用时间对象作为域值会导致数据映射完全错位,进而破坏可视化效果。

修复代码

把x轴编码里的scale.domain改成纯数值范围[0, 24]就行,调整后的代码片段:

"x": {
  "field": "timestamp",
  "type": "temporal",
  "timeUnit": "hours",
  "scale": {"domain": [0, 24]},
  "axis": {"title": "时间(小时)"}
}

补充说明

  • 如果不想用timeUnit,也可以直接基于完整时间戳设置域,用ISO格式的字符串就行,比如:
    "x": {
      "field": "timestamp",
      "type": "temporal",
      "scale": {"domain": ["2023-01-01T00:00:00", "2023-01-02T00:00:00"]},
      "axis": {"title": "时间", "format": "%H:%M"}
    }
    
    这种方式不需要timeUnit,轴上的时间格式可以通过axis.format自定义。

内容的提问来源于stack exchange,提问作者llermaly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 22:20:47