首页 > 解决方案 > 散景图:通过选定的条形图更改线图

问题描述

我一直在寻找,但还没有找到有效的答案,所以我想我会问。

问题

一切都符合规范,除非我单击 statesbp hbar 图,我似乎无法触发获取所选柱值的回调函数(在本例中为 hbar_select)。我在回调函数中添加了一个打印语句,当服务器运行时,我没有在终端中看到这个触发。

我需要做什么才能通过回调选择条形图?

提前致谢,

富有的

hbar_source = ColumnDataSource(data=dict(state=[], sessions=[],))
hbartools = 'tap'
statesbp = figure(y_range=state_data.sort_values('sessions')['state'].values,plot_width=300,plot_height=500, tools='tap', title='Sessions By State')
statesbp.x_range.start = 0
statesbp.hbar(y='state', right='sessions', height=.5, color='navy', source=hbar_source)

def update(selected=None):
    data = get_data(state=selected)
    source.data = source.from_df(data)
    source_static.data = source.data
    ts1.title.text = selected

def hbar_select(attrname, old, new):
    index_of_selected = new['1d']['indices'][0]
    print(index_of_selected)
    update(selected = index_of_selected)

def update_hbar():
    data = get_states()
    hbar_source.data = hbar_source.from_df(data)


#on hbar select, update line chart
hbar_source.on_change('selected',hbar_select)

# initialize data
update()
update_hbar()

curdoc().add_root(series)
curdoc().title = "Website Visits"

散景工作图

标签: python-3.xbokeh

解决方案


现在您正在寻找更改,hbar_source.selected但这不会改变,它将始终是一个 Selection 对象!您应该将此行更改为hbar_source.selected.on_change('indices',hbar_select). 当您选择一个条到ColumnDataSource.


推荐阅读