Altair graph- streamlit

Google Sheet for this data

Dear everyone,

I would like to ask how to fix x-axis value to visualize with only month including June, July, August, September, and October and then fill with line graph of respective years (1992,1998,2000,2020,2021,2022) in my googlesheet. I am using Altair library. Thank you for your time on helping on this.

The current code is:

Define the base time-series chart for testing.

def get_chart(source):
hover = alt.selection_single(
fields=[“d”],
nearest=True,
on=“mouseover”,
empty=“none”,
)

lines = (
    alt.Chart(source, title="Water Level (m) for Stung Treng")
    .mark_line()
    .encode(
        x=alt.X("d:T", title="Date in DD/MM "),
        y=alt.Y("wl", title= "Water Level in meter", scale=alt.Scale(zero=False)),
        color="cat",
        # strokeDash="Year",
    )
)

# Draw points on the line, and highlight based on selection

points = lines.transform_filter(hover).mark_circle(size=65)

# Draw a rule at the location of the selection

tooltips = (
    alt.Chart(source)
    .mark_rule()
    .encode(
        x="d",
        y="wl",
        opacity=alt.condition(hover, alt.value(0.9), alt.value(0)),
        tooltip=[
            alt.Tooltip("d", title="Date"),
            alt.Tooltip("wl", title="Water Level"),
        ],
    )
    .add_selection(hover)
)
return (lines + points + tooltips ).interactive()

chart3 = get_chart(source)

st.altair_chart(
(chart3 ).interactive(),
use_container_width=True
)


Ask the community or our support engineers for answers to questions.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.