我正在尝试散景数据表.是否可以将HoverTool添加到散景表中的每个字段?
DataTable的一个例子 -
以及HoverTool如何工作的例子 -
这可以使用HTMLTemplateFormatter
:
main.py:
from os.path import dirname, join
import pandas as pd
from bokeh.io import curdoc, show
from bokeh.models import ColumnDataSource, Div
from bokeh.models.widgets import DataTable, TableColumn, HTMLTemplateFormatter
from bokeh.layouts import layout
template = """<%= value %>"""
df = pd.DataFrame([
['this is a longer text that needs a tooltip, because otherwise we do not see the whole text', 'this is a short text'],
['this is another loooooooooooooooong text that needs a tooltip', 'not much here'],
], columns=['a', 'b'])
columns = [TableColumn(field=c, title=c, a', 'b']]
table = DataTable(source=ColumnDataSource(df), columns=columns)
l = layout([[table]])
curdoc().add_root(l)
show(l)
一种稍微好一点的方式(虽然有点痛苦)会使用不同的模板和一些CSS样式.
template = """"""<%= value %><%= value %>
desc.html:
Tooltip demo