Altair chart out of container while container_width set true

Summary

Problem is my chart has many columns, is there a way my chart’s width is set to his container because it’s out of his container now.

Steps to reproduce

Code snippet:

from vega_datasets import data
source = data.barley()

b = alt.Chart(source).mark_bar().encode(
    x=alt.X('year:O', title=None),
    y='yield:Q',
    color='variety:N',
    column=alt.Column('site:N', title=None,
                      header=alt.Header(labelColor='blue'))
)
st.altair_chart(b, use_container_width=True)

Expected behavior:

Chart should be inside the container, no scrolling needed.

Additional information

1 Like

To ensure that the chart fits inside its container, you can set the width property of the chart to "container" using Altair. Here’s the modified code:

import altair as alt
from vega_datasets import data
source = data.barley()

b = alt.Chart(source).mark_bar().encode(
    x=alt.X('year:O', title=None),
    y='yield:Q',
    color='variety:N',
    column=alt.Column('site:N', title=None,
                      header=alt.Header(labelColor='blue'))
).properties(width='container')

st.altair_chart(b)

I’ve tried that, not the result we really want :smiley:

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