【发布时间】:2019-11-05 17:46:12
【问题描述】:
我正在尝试根据堆叠图表上的数据创建自定义悬停。在下面的示例中,如果用户将鼠标悬停在“cat1”上,则应返回“cat1_text”; 'cat2_text' 和 'cat3_text' 对应 'cat2' 和 'cat3'。
对于工具提示,由于 $name 将返回 'cat1'、'cat2' 或 'cat3',我认为通过添加 '_text',将相应地调用该值(但当然这似乎不是python/bokeh 的工作方式)。我也在考虑使用任何函数/索引调用,但不太确定该怎么做。友善的建议。非常感谢!
category = ['cat1', 'cat2', 'cat3']
data = {'timeVal' : [0,1,2,3,4,5],
'cat1' : [2, 1, 4, 3, 2, 4],
'cat2' : [5, 3, 4, 2, 4, 6],
'cat3' : [3, 2, 4, 4, 5, 3],
'cat1_text' : ['a','b','c','d','e','f'],
'cat2_text' : ['a1','b1','c1','d1','e1','f1'],
'cat3_text' : ['a2','b2','c2','d2','e2','f2'],
}
toolTipArr = [
("name", "$name"),
("count", "@$name"),
("info", '@'+'$name'+'_text}')
]
p = figure(x_range=(startTime,endTime), plot_height=250, plot_width=1000, title="project",
toolbar_location="right", tools="hover,pan,wheel_zoom,box_zoom,reset",
tooltips=toolTipArr)
p.vbar_stack(category, x='timeVal', width=2, color=colors, source=data,
legend=[value(x) for x in category])
【问题讨论】:
标签: python bar-chart bokeh stacked-chart