I am trying to build a bar chart where I have three legends (so three different bar charts) combined with a hoverTool.
At the moment I have build the bar charts with the legend, however I am having problems with the HoverTool. In the code showed below the hover tool shows all three tooltips for all of the charts. I only want the hovertool to show one of the tooltips, so for example for the bar chart 'popPerc' I only want to see '@population' in the hover tool.
p = figure(x_range=df2.district,plot_height=300,plot_width=500,
y_range= ranges.Range1d(start=0,end=25))
p.xgrid.grid_line_color=None
p.ygrid.grid_line_color=None
p.y_range.start = 0
p.xaxis.major_label_orientation = 0.5
p.yaxis.visible = False
p.toolbar_location=None
p.outline_line_color = None
colors = all_palettes['BuGn'][3]
bar = {}
items = []
color = 0
features = ['popPerc','areaPerc','treesPerc']
for indx,i in enumerate(features):
bar[i] = p.vbar(x='district', top=i, source=df2, muted_alpha=0, muted=False,
width= 0.8, color=colors[color])
items.append((i,[bar[i]]))
color+=1
legend = Legend(items=items,location=(0,100))
p.add_tools(HoverTool(tooltips = [('Trees','@trees'),
('Population','@population'),
('Area [km^2]','@area')]))
p.add_layout(legend,'left')
p.legend.click_policy='hide'
show(p)
Hope that someone can help, thanks in advance! :)
After reading up on the article sugested I figured it out. By changing the code block for the hovertool to the following it works.
p.add_tools(HoverTool(renderers=[items[0][1][0]], tooltips = [('Population','@population')]))
p.add_tools(HoverTool(renderers=[items[1][1][0]], tooltips = [('Area [km^2]','@area')]))
p.add_tools(HoverTool(renderers=[items[2][1][0]], tooltips = [('Trees','@trees @treePerc')]))