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

如何在Vega 1.5.0的Text Mark中显示两个不同值?

Displaying Combined Text (e.g. Name: Value) in Vega 1.5.0 Text Marks

I’ve dug into your issue, and here’s a clear breakdown of what’s going on and your available options:

What You’re Trying to Do

You want to render combined text like Name: Value in a Vega 1.5.0 Text Mark, but can’t get two separate data fields to display together as intended.

Why Your Attempts Didn’t Work

  • Duplicate field keys: When you tried "text": {"field": "data.name", "field": "data.value" }, JSON’s core behavior overwrites duplicate keys—only the last field entry gets processed, so your first value gets completely ignored.
  • Calculate transform limitations: The calculate transform you tested:
    { "calculate": "data.name + ':' + data.value", "as": "tooltip" }
    
    fails because Vega 1.5.0 is an extremely outdated release that doesn’t support this transform type. Its expression handling also doesn’t allow string concatenation in this format.

Final Verdict

Unfortunately, Vega 1.5.0 does not support combining multiple data fields in a Text Mark—there’s no built-in way to achieve your desired Name: Value format with this version. The only reliable solution is to upgrade to a newer release of Vega (we recommend v5 or later). In newer versions, you have two straightforward options:

  1. Use the calculate transform to pre-combine the string into a new field, then reference that field in your Text Mark
  2. Use an inline expression directly in the text property, like:
    "text": {"expr": "datum.name + ': ' + datum.value"}
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 14:12:50