我正在尝试按照Multi-Line Tooltip 示例的线条创建一个图表,但我想格式化正在打印的字符串以在末尾添加一些文本。我正在尝试修改这部分:
# Draw text labels near the points, and highlight based on selection
text = line.mark_text(align='left', dx=5, dy=-5).encode(
text=alt.condition(nearest, 'y:Q', alt.value(' '))
)
具体来说,我想要的不是'y:Q',而是'y:Q'+“后缀”。我试过做这样的事情:
# Draw text labels near the points, and highlight based on selection
text = line.mark_text(align='left', dx=5, dy=-5).encode(
text=alt.condition(nearest, 'y:Q', alt.value(' '), format=".2f inches")
)
或者,我尝试过:
# Draw text labels near the points, and highlight based on selection
y_fld = 'y'
text = line.mark_text(align='left', dx=5, dy=-5).encode(
text=alt.condition(nearest, f"{y_fld:.2f} inches", alt.value(' '))
)
我想我明白为什么这些不起作用,但我不知道如何截取 y 的值并通过格式字符串传递它。谢谢!