问题描述
我正在使用 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"}
}
}
是否可以在此值前添加一些文本并在其后添加 % 符号?
解决方法
添加这种复杂注释的最佳方法是使用 calculate transform;例如:
{
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"}
}
}