如何在单行显示中组合文本和字段值

Not*_*ica 4 vega vega-lite

我正在使用 Vega,但我陷入了这个简单的问题。我要显示

The yield is 43.67%

但是,使用提供的示例,我成功地仅显示了值 43.67

{
  mark:
    {
      type: "text",
      align: "center",
      fontSize: 40,
      fontWeight: "bold"
    },
  encoding: 
    {
      "text": {"field": "Yield", "type": "quantitative",format: ".2f"}
    }
}
Run Code Online (Sandbox Code Playgroud)

是否可以在此值前面添加一些文本并在其后面放置一个 % 符号?

jak*_*vdp 7

添加此类复杂注释的最佳方法是使用计算转换;例如:

{
  mark:
    {
      type: "text",
      align: "center",
      fontSize: 40,
      fontWeight: "bold"
    },
  transform:
    [
      {"calculate": "'The yield is ' + datum.Yield + '%'", "as": "annotated_yield"}
    ],
  encoding: 
    {
      "text": {"field": "annotated_yield", "type": "nominal"}
    }
}
Run Code Online (Sandbox Code Playgroud)