Thanks to visit codestin.com
Credit goes to github.com

Skip to content

st.line_chart uses columns in wrong order #12071

@yellowdolphin

Description

@yellowdolphin

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

In a multi-line plot, st.line_chart() always re-orders the columns in data, presumably in alphanumeric order. This leads to wrong assignments of color and column names appear in the legend in wrong order.

Reproducible Code Example

# line_chart_bug.py
import streamlit as st

chart_data = {'c_one': [1, 1, 1], 'b_two': [2, 2, 2], 'a_three': [3, 3, 3]}
st.line_chart(
    chart_data, 
    y=['c_one', 'b_two', 'a_three'], 
    color=[(255, 0, 0), (0, 255, 0), (0, 0, 255)]
)

Steps To Reproduce

$ streamlit run line_chart_bug.py

Expected Behavior

kwarg y should determine the order of columns in the plot and when omitted/None, columns should be plotted in the same order as the column index.

Current Behavior

  • Legend shows columns in wrong order: "a_three", ... which depends entirely on column names, not the order of the sequence y
  • Colors in color are assigned to the wrong lines: "c_one" should be red not blue.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.39 ... 1.47.1 (all tested)
  • pandas 2.2.3
  • Python version: 3.12.7
  • Operating System: ubuntu 24.04
  • Browser: chrome-based

Additional Information

Temporary workaround: you can modify the column order by prepending column names with spaces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:st.altair_chartRelated to the `st.altair_chart` elementpriority:P2Medium-high priority - fix within one monthstatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions