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