如何在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
fieldkeys: When you tried"text": {"field": "data.name", "field": "data.value" }, JSON’s core behavior overwrites duplicate keys—only the lastfieldentry gets processed, so your first value gets completely ignored. - Calculate transform limitations: The calculate transform you tested:
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.{ "calculate": "data.name + ':' + data.value", "as": "tooltip" }
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:
- Use the calculate transform to pre-combine the string into a new field, then reference that field in your Text Mark
- Use an inline expression directly in the text property, like:
"text": {"expr": "datum.name + ': ' + datum.value"}
内容的提问来源于stack exchange,提问作者QbA
相关产品推荐
相关产品推荐

