Line chart with Month in X axis

Hello ,
i have a dataframe with 3 columns and i want to plot a line chart where the Month is
the X axis … and i want to sum the values in the y axis … below codes are showing months not sequential ( march is coming first instead of jan… ) and it’s not summing the value for example of the lab charges and the outpatient consultation charges.
can you please help ?

dft1 = dfp[['Monthy ','outpatient_consultation ','Lab_charges ']]
dft1 = dft1.set_index('Monthy ')
st.line_chart(dft1)

pic

Hi @johny_achkar, welcome to the Streamlit forum! There are possibly two things to try here…

First, is the data in the Monthy column strings or Python datetimes? If the data are strings, then it might be confusing the underlying plotting logic.

Second, from a general Streamlit perspective, is that the st.line_chart (along with st.bar_chart, st.area_chart and the like) are convenience functions around st.altair_chart. So in the case that you’re not getting the correct behavior for the plot you’re looking to generate, you can use st.altair_chart to specify the exact Altair logic to sort axes the way you want, change colors, etc.

https://altair-viz.github.io/gallery/simple_line_chart.html

Best,
Randy

2 Likes

thank you @randyzwitch … you gave me the hint … in fact i converted Monthy column to panda data time using : dfp['Monthy ']=pd.to_datetime(dfp['Monthy '])
and it worked … it was an object prior to converting it …you’re right.

1 Like