Hi everyone,
I hope that I’m right here in this section asking for help. If not, then please apologize this post.
I try to create a bar chart having products on the Y axis and their delay on the X axis. Any product exceeding its defined maximum delay should be shown in a different color (i.e. red), while everything else may be shown in green color.
What I already got is a bar chart, sorted by their overdue values but I’m not able to apply a different color on specific bars.
Here’s the current dataframe df_to_display
:
PRODUKT CURRENT_DELAY OVERDUE
6 C 546 False
5 A 76 False
17 X 27 True
12 T 21 True
11 S 3 True
3 M 3 True
14 V 3 False
7 R 3 True
Those products having OVERDUE == True should be displayed with a red bar, all others in green.
The code for the bar chart I’ve got so far is this:
st.altair_chart(
alt.Chart(df_to_display)
.mark_bar()
.encode(
x=alt.X("CURRENT_DELAY", axis=alt.Axis(title="Current Delay (days)")),
y=alt.Y(
"PRODUKT",
axis=alt.Axis(title="Product"),
sort=alt.EncodingSortField(field="CURRENT_DELAY", order="descending"),
),
),
use_container_width=True,
)
Does anyone have a tip for me on how to do that?
I’m using:
Streamlit 1.41.1
Altair 5.5.0
Python 3.9
Many thanks in advance!