Reputation: 3
I am new to bokeh
and facing some problem with hover feature.
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.transform import dodge
output_file("dodged_bars.html")
fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
years = ['2015', '2016', '2017']
data = {'fruits' : fruits,
'2015' : [2, 1, 4, 3, 2, 4],
'2016' : [5, 3, 3, 2, 4, 6],
'2017' : [3, 2, 4, 4, 5, 3]}
source = ColumnDataSource(data=data)
p = figure(x_range=fruits, y_range=(0, 10), plot_height=250, title="Fruit counts by year",
toolbar_location=None, tools="")
p.vbar(x=dodge('fruits', -0.25, range=p.x_range), top='2015', width=0.2, source=source,
color="#c9d9d3", legend_label="2015")
p.vbar(x=dodge('fruits', 0.0, range=p.x_range), top='2016', width=0.2, source=source,
color="#718dbf", legend_label="2016")
p.vbar(x=dodge('fruits', 0.25, range=p.x_range), top='2017', width=0.2, source=source,
color="#e84d60", legend_label="2017")
hover = HoverTool()
hover.tooltips = """
<div>
<div><strong>fruits: </strong>@fruits</div>
<div><strong>Count: </strong>@name</div>
</div>"""
p.add_tools(hover)
p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.legend.location = "top_left"
p.legend.orientation = "horizontal"
show(p)
Please help me understand how to add hover feature for multigraph.i guess glyph or something else is missing
In this image ??? shows instead of value.
Upvotes: 0
Views: 572
Reputation: 743
p.vbar(... name='2015',legend_label="2015")
p.vbar(... name='2016',legend_label="2016")
p.vbar(... name='2017',legend_label="2017")
and
<div>
<div><strong>fruits: </strong>@fruits</div>
<div><strong>Count: </strong> @$name</div>
</div>
Upvotes: 1