1
我有一個簡單的ColumnDataSource多列,每列表示一個模擬的不同日子,每一行代表具有狀態a,b,c等的實體的數量。我希望能夠用滑塊擦洗日子(列)。使用帶滑塊的CustomJS回調繪製不同的列
我已經採取一看1,2和散景docs的信息,但我一直沒能成功地得到它的工作。我有以下代碼(最小):
from bokeh.plotting import figure
from bokeh.layouts import column, widgetbox
from bokeh.models import CustomJS, Slider, ColumnDataSource, ranges
from bokeh.io import output_file, show
output_file("barplot.html")
sim_time=4
data = {'x': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
'0': [2860.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
'1': [2860.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
'2': [0.0, 2860.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
'3': [0.0, 2860.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}
source = ColumnDataSource(data)
barplot = figure(plot_width=800, plot_height=600, tools='pan', x_axis_label='Status', x_range=source.data['x'], y_range=ranges.Range1d(start=0, end=3000))
barplot.vbar(source=source, x='x', top='0', width=0.6)
callback = CustomJS(args={'source':source}, code="""
console.log(' changed selected time', cb_obj.value);
var data = source.data;
data['0'] = data[cb_obj.value];
source.change.emit()
""")
time_slider = Slider(start=0, end=sim_time-1, value=1, step=1, callback=callback)
callback.args["time"] = time_slider
show(column(barplot, time_slider))
即我無法使用滑塊遍歷列。
我在做什麼錯?
乾杯
我很欣賞快速回復!我應用了所有建議,但擦洗仍然無效。在查看瀏覽器控制檯時,它告訴我source.change.emit()拋出了「undefined不是對象」的TypeErrors。有什麼想法嗎? – okurniawan
解決了這個問題 - 這個功能在散景0.12.5上被打破,但在0.12.7上功能完整。 – okurniawan