所以我有一个条形图,上面有一条线。它工作正常,除了我无法使hovertool在添加的折线图上工作。我不确定如何完成下面的代码以使鼠标悬停在该行上。任何帮助将不胜感激。
def distance_to(poi2, way)
distance_sql = <<-SQL
SELECT
ST_3DDistance(way.path::geometry, pta.lonlat::geometry) +
ST_3DDistance(way.path::geometry, ptb.lonlat::geometry) +
ST_Length(ST_LineSubstring(
way.path,
least(ST_LineLocatePoint(way.path, pta.lonlat::geometry), ST_LineLocatePoint(way.path, ptb.lonlat::geometry)),
greatest(ST_LineLocatePoint(way.path, pta.lonlat::geometry), ST_LineLocatePoint(way.path, ptb.lonlat::geometry)))::geography) AS dst_line
FROM ways way, pois pta, pois ptb
WHERE way.id = #{way.id}
AND pta.id = #{self.id}
AND ptb.id = #{poi2.id}
SQL
Poi.find_by_sql(distance_sql).first.dst_line
end
答案 0 :(得分:2)
弄清楚了。我必须对条和行都使用add_tools方法,才能为两者添加HoverTool。
更新的图形不包含任何悬停参数。给条形图一个变量名,然后用它来添加悬停工具。
p = figure(plot_width=500, plot_height=400, x_range=m1)
bar = p.vbar(x='x', width=0.5, bottom=0, top='y', color="#B3DE69", source=source_net_rev)
p.add_tools(HoverTool(renderers=[bar], tooltips=tooltip_net_rev))
与折线图相同
line = p.line(x='x', y='y', line_width=2, y_range_name="Vol", color="black", source=source_vol)
p.add_tools(HoverTool(renderers=[line], tooltips=tooltip_net_vol))