如何在 Python Altair Chart.save(file.html) 生成的 n Altair Chart 的 html 文件中显示默认工具提示?

How to display the default tooltip on the html file of a n Altair Chart generated by Python Altair Chart.save(file.html)?

以 HTML 格式保存在 Python Altair 中生成的图表后,HTML 版本似乎没有默认工具提示。

当我在 Jupyter 中 运行 这段代码时,我可以在 Jupyter 输出中看到工具提示。但是当我在浏览器中打开 bar.html 文件时,当我将鼠标悬停在图表上时没有显示工具提示。

import altair as alt
from vega_datasets import data

barley = data.barley()

chart = alt.Chart(barley).mark_bar().encode(
    x='variety:N',
    y='sum(yield):Q',
    color='site:N',
    order=alt.Order("site", sort="ascending")
)
chart.save('bar.html')
chart

我阅读了有关工具提示的 Vega Lite 文档。我为工具提示添加了脚本标签,但我仍然无法使其工作。我做错了什么?有没有更简单的方法来添加默认工具提示?提前致谢。

<script src="https://cdn.jsdelivr.net/npm/vega-tooltip"></script>

....

var embed_opt = {"mode": "vega-lite", tooltip: {theme: 'dark'}};
vegaEmbed("#vis", spec, embed_opt)
        .catch(error => showError(el, error));

仅 Vega-Lite 版本 3 支持默认工具提示。Altair 目前支持 Vega-Lite 版本 2.6。

您在 JupyterLab 中看到默认工具提示的原因是 jupyterlab vega 扩展在其最新版本中错误地包含了 Vega-Lite 3。该错误正在此处更正:https://github.com/jupyterlab/jupyterlab/pull/5342