Altair stacked bar graph width problem


The generated graphic does not shrink itself horizontally. This causes it to overflow the page.

Steps to reproduce

Code snippet:

import streamlit as st
import pandas as pd
import altair as alt

source = pd.read_excel('database_.xlsx')
# database file

chart = alt.Chart(source).mark_bar().encode(
    x=alt.X("MACHINE:O", title=None, axis=alt.Axis(labels=False)),
    column=alt.Column('DATE', title=None, header=alt.Header(orient='bottom', format="%Y - %m - %d", labelAngle=270, labelPadding=80, labelFontSize=13, labelColor='Gray'))

st.altair_chart(chart, theme="streamlit", use_container_width=False)

Debug info

  • Streamlit version: (version 1.17.0)
  • Python version: (Python 3.9.10)

Is there a way to make it look like other charts? Thank you.

Have you tried set use_container_width = True ?

Yes. I think it is about bar width.

My streamlit version is 1.13.0 Altair 4.2.0 , I am not sure if this causes the problem
But in my case use_containers_width param works fine

Hi @oliverjia. There is no param as โ€˜use_containers_widthโ€™. I think you typed it by mistake. Param name is โ€˜use_container_widthโ€™ without s letter. As I said, it changes only the bar width.

Hi @volkan ,

Would you maybe want to try changing the properties to a specific width?


Hi @willhuang ,

mark_bar(size=30) this code is changing the bar width for me. Also, I donโ€™t want to use certain width parameters as I donโ€™t want to restrict the view in different browsers and devices.

Interestingly, I still havenโ€™t found a solution to the problem.

Hi, the mark_bar parameter is working or not working?

It is working.

mark_bar size-2

mark_bar(size=2) for the first image and mark_bar(size=20) for the second image. As a result, no matter how much I change this parameter, I think it has nothing to do with my problem.

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