简体   繁体   中英

Altair interactive filter on multiple values of one column

Here is the code of my plot.

input_dropdown = alt.binding_select(options=[None]+all_ids, name='Series ID', labels=["All"]+all_ids)
selection = alt.selection_single(fields=['ID'], bind=input_dropdown)

chart = alt.Chart(source_df).mark_line().encode(
    x=alt.X('Date:T', title='Date'),
    y=alt.Y('Value:Q', title='Value'),
    color = alt.Color('ID:N', title='Series ID'),
    strokeDash='Type:N'
).properties(
    width=700
).add_selection(
    selection
).transform_filter(
    selection
)

st.altair_chart(chart)

Currently I can filter data displayed by choosing one value of ID column. What should I do to filter by multiple ID values?

Smth like, show me the data for both ids '1' and '2'.

This is currently not possible via a widget like a dropdown because it is not implemented in the underlying Vega and Vega-Lite libraries . You could another chart as a selection element, or maybe use a streamlit component since it looks like your code is using that library already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM