Change chart type and data using dropdown menu

i tried to use dropdown button to select between line graph for trend and horizontal bar for binning.

trend:

binning;

after combine both with ‘update’ or ‘restyle’ method the binning chart is not displayed prorperly.

any solution for this?

1 Like

if i change it to vertical bar chart instead of horizontal bar chart it will behave correctly. i guess the reason behind is the yaxis and xaxis type was swapped when in horizontal bar case. i still haven’t found the solution yet.

just found a solution by manually set the xaxis and yaxis type and with method ‘update+relayout’

bin_trend_buttons.append(
    dict(label='buckets', method='update+relayout',
            args=[{'visible': [True] * 7 + [False] * 2, 'xaxis':{'type':'category'}, 'yaxis':{'type':'linear'}}]))
bin_trend_buttons.append(
    dict(label='trend', method='update+relayout',
            args=[{'visible': [False] * 7 + [True] * 2, 'xaxis':{'type':'linear'}, 'yaxis':{'type':'category'}}]))

This looks like a question for #api:python

thanks for pointing out.

i am hitting into another problem. let’s say i have 3 buttons in my updatemenus and the first two i wish to make it stacked bar chart while the last one with barmode = ‘group’. my try many way to code it but still not successful =.="

buttons.append(dict(label='vt-varient', method='update',
            args=[{'visible': [True] * col_count[0] + [False] * col_count[1] + [False] * col_count[2]}]))
                # {'layout':{'barmode':'stack', 'barnorm':'percent'}}]))
buttons.append(dict(label='cell-type', method='update',
            args=[{'visible': [False] * col_count[0] + [True] * col_count[1] + [False] * col_count[2]}]))
                # {'layout':{'barmode':'stack', 'barnorm':'percent'}}]))
buttons.append(dict(label='cell-count', method='update+relayout',
            args=[{'visible': [False] * col_count[0] + [False] * col_count[1] + [True] * col_count[2]}, {'barmode':'group'}]))

resolved with this code :slight_smile:

buttons = []
buttons.append(dict(label='vt-varient', method='update',
            args=[{'visible': [True] * col_count[0] + [False] * col_count[1] + [False] * col_count[2]}, 
                {'barmode':'stack', 'barnorm':'percent'}]))
buttons.append(dict(label='cell-type', method='update',
            args=[{'visible': [False] * col_count[0] + [True] * col_count[1] + [False] * col_count[2]}, 
                {'barmode':'stack', 'barnorm':'percent'}]))
buttons.append(dict(label='cell-count', method='update',
            args=[{'visible': [False] * col_count[0] + [False] * col_count[1] + [True] * col_count[2]}, 
                {'barmode':'group', 'barnorm':''}]))