Monday, 21 September 2020

Synchronize legend items visibility across charts

How can i synchronize series visibility across charts, such that when user show/hide series in one chart, all the others chart's series visibility change as well

charts = []
renderers = []

#iterate over and gather all legend renderers
for spec in charts_specs:
    chart = createChart(spec)
    charts.append(chart)
    for legend in chart.legend:
        for legend_item in legend.items:
            renderers.append(legend_item.renderers[0])

#register for visibility changed and update matching legends in other charts
for renderer in renderers:
    renderer.js_on_change("visible", CustomJS(args=(renderer=renderer, renderers = renderers), code = """
    
    for(var index =0 ; index < renderers.length; index++)
    {
       var global_renderer = renderers[index];
       if(global_renderer.name === renderer.name)
       {
            global.renderer.visible = renderer.visible
       }
    }
    """)

#plot charts
for chart in charts:
    show(chart)

Question - with above (1) I do not see anything update (2) Why does this not cause a stack overflow with visiblity callback called recursively. I suppose i am not pushing the changes correctly?



from Synchronize legend items visibility across charts

No comments:

Post a Comment