【发布时间】:2019-04-28 07:13:23
【问题描述】:
我正在尝试创建一个有点类似于Multi-Line Tooltip example 的图表,但我想格式化正在打印的字符串以在末尾添加一些文本。我正在尝试修改这部分:
# 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 的值并通过格式字符串传递它。谢谢!
【问题讨论】:
标签: altair