[英]Can not get any Bokeh graphs show up when the check boxes are ticked
我已经尝试了下面的代码来为每个元素生成散景图,当它们各自的复选框被选中时。 数据是一个 df,其中包含“id”、“data_point”、“max”、“min”等列在 id 旁边,图表应该显示复选框选择的任何 id 这应该发生在每个唯一 id 上。 对于一个唯一的 id,图表应该如下所示
data = df
if len(data) == 0:
logging.debug(" No data")
else:
req_hover = HoverTool(
tooltips=[
('data_point: ', '@data_point'),
('id: ', '@id')])
req_figure = figure(title='Graph', x_axis_label="Index", y_axis_label="id/data_point [ms]",
plot_width=800, plot_height=400, output_backend="webgl")
req_figure.add_tools(handover_hover)
id_values = data['id'].drop_duplicates()
column_view_data = data[
['id', 'tag', 'sw', 'name']].drop_duplicates().dropna()
column_view_data_source = ColumnDataSource(column_view_data)
data_table = DataTable(selectable='checkbox', source=column_view_data_source, columns=columns, width=1450,
height=400, css_classes=['blueTable'])
name_dict_req = {'name': [], 'legend': [], 'label': []}
logging.info('START OF DRAWINGS')
for ind, element in enumerate(elements):
d = []
for i, item in data.iterrows():
it_color = Turbo256[random.randint(0, 255)]
if element == item['id']:
if item['data_point'] is None or str(item['data_point']) == '[]':
item['data_point'] = '0'
else:
item['data_point'] = [float(x) for x in item['data_point'].strip('[').strip(']').split(',')]
raw_data_element_count = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20] # this is my x axis which will be 1 to 20
d.append({'id': id,
'number of raw data points': data_point_element_count,
'data_point': item['data_point']})
d_new = pd.DataFrame(d)
name_glyph_req = req_figure.line(x='number of raw data points',
y='data_point',
line_width=2,
legend_label=str(item['id']),
source=d_new,
color=it_color)
name_dict_req['name'].append(name_glyph_req)
name_dict_req['label'].append(str(item['id']))
logging.info('AFTER DRAWINGS LOOP')
for label in range(len(data.id.unique())):
name_dict_req['legend'].append(req_figure.legend.items[label])
initial_value = []
options = list(data.id.unique())
for i, name in enumerate(options):
options[i] = str(name)
for i in range(len(options)):
if name_dict_req['label'][i] in initial_value:
name_dict_req['name'][i].visible = True
name_dict_req['legend'][i].visible = True
else:
name_dict_req['name'][i].visible = False
name_dict_req['legend'][i].visible = False
#########################
callback_datatable = CustomJS(args=dict(source=column_view_data_source), code=callback_file_content_mq)
###################
column_view_data_source.selected.js_on_change('indices', callback_datatable)
req_figure.legend.location = "top_left"
req_figure.legend.click_policy = "hide"
logging.info('END DRAWINGS END SETUP')
我想我没有在我的代码中的 customJS 调用中提供名称字典。 所以问题就在那里,即使我点击复选框,图表也没有显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.