2017-07-28 25 views
2

我已爲我的數據集啓用了隱藏圖例選項。當我點擊它時,只有一個酒吧熄滅,其他酒吧停留。我不太確定是什麼導致了這個問題。散景互動圖例隱藏多個字形

這裏的酒吧情節前後:

before and after

這裏是我的數據是這樣的:

Here's

下面的代碼:

p = Bar(output,'Programs',values="Averages", group="University",plot_width=600,plot_height=400, title="Comparison") 
p.legend.click_policy="hide" 
output_file("bar.html") 
show(p) 

回答

0

它不是當前(背景虛化0.12.6)可以通過legend.click_policy="hide"隱藏所有的酒吧,如documentation中所述:

Interactive傳說中的功能目前用於「每個字形」的傳說。由指定列創建傳說自動組做沒有尚未與下面

據,但是,能夠通過與該隱藏杆CustomJS添加CheckboxGroup()隱藏杆被點擊複選框時所描述的功能的工作。以下您可以看到一個MCVE,這也是available online as a Jupyter Notebook

import numpy as np 
from bkcharts import Bar, show 
from bokeh.layouts import column 
from bokeh.models import CheckboxGroup, CustomJS 

data = {'University': ['ENGT'] * 3 + ['UBC'] * 3, 
     'Averages': [76.5, 79.9, 72.2, 71, 72, 69], 
     'Programs': ['CHML', 'CIVL', 'CPEN', 'CHML', 'CIVL', 'CPEN']} 

group = "University" 
bars = Bar(data=data, label='Programs', values="Averages", group=group, 
      plot_width=600, plot_height=400, title="Comparison") 

checkboxes = CheckboxGroup(labels=np.unique(data[group]).tolist(), 
          # Make all checkboxes checked by default 
          active=list(range(np.unique(data[group]).size))) 
checkboxes.callback = CustomJS(args=dict(bars=bars), code=""" 

var group = '%s'; 

function change_bars_visibility(checkbox_name, visible) { 
    for (j = 0; j < bars.renderers.length; j++) { 
     // Go through rendered objects 

     if (bars.renderers[j].attributes.hasOwnProperty('data_source') && 
      bars.renderers[j].data_source.data[group][0] === checkbox_name) { 

      // Change the visibility of this rendered object if it belongs to 
      // the group determined by the checkbox that was clicked 
      bars.renderers[j].visible = visible; 
     } 
    } 
} 

for (i = 0; i < cb_obj.labels.length; i++) { 
    // Go through checkbox labels 
    var checkbox_name = cb_obj.labels[i]; 

    if (cb_obj.active.indexOf(i) >= 0) { 
     // alert(checkbox_name + " is activated"); 
     change_bars_visibility(checkbox_name, true); 
    } 
    else { 
     // alert(checkbox_name + " is disabled"); 
     change_bars_visibility(checkbox_name, false); 
    } 
} 
""" % group) 

show(column(bars, checkboxes))