Repository: streamlit/streamlit

Issue:
Default bar chart should use ordinal scale for categorial data
# Summary

The default bar chart should use an ordinal scale so that the style is correct. 

# Steps to reproduce

```py
import streamlit as st
import pandas as pd
import numpy as np

st.title('Uber pickups in NYC')

DATE_COLUMN = 'date/time'
DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
            'streamlit-demo-data/uber-raw-data-sep14.csv.gz')

@st.cache
def load_data(nrows):
    data = pd.read_csv(DATA_URL, nrows=nrows)
    lowercase = lambda x: str(x).lower()
    data.rename(lowercase, axis='columns', inplace=True)
    data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
    return data

data_load_state = st.text('Loading data...')
data = load_data(10000)
data_load_state.text("Done! (using st.cache)")

if st.checkbox('Show raw data'):
    st.subheader('Raw data')
    st.write(data)

st.subheader('Number of pickups by hour')
hist_values = np.histogram(data[DATE_COLUMN].dt.hour, bins=24, range=(0,24))[0]
st.bar_chart(hist_values)
```

## Expected behavior:

<img width="543" alt="Screen Shot 2020-10-05 at 18 36 17" src="https://user-images.githubusercontent.com/589034/95149008-abb18400-0739-11eb-9e34-588dab443af8.png">

## Actual behavior:

<img width="658" alt="Screen Shot 2020-10-05 at 18 36 13" src="https://user-images.githubusercontent.com/589034/95149011-aeac7480-0739-11eb-9436-7d37d7f398a5.png">


# Debug info

- Streamlit version: 0.65.2



Discussion:
Agree that the lines on the bar chart look too thin, and ordinal scale sounds like a good fix.

Resolving patch:
diff --git a/docs/api-examples-source/layout.expander.py b/docs/api-examples-source/layout.expander.py
--- a/docs/api-examples-source/layout.expander.py
+++ b/docs/api-examples-source/layout.expander.py
@@ -1,6 +1,6 @@
 import streamlit as st
 
-st.line_chart({"d6": [1, 5, 2, 6, 2, 1]})
+st.bar_chart({"d6": [1, 5, 2, 6, 2, 1]})
 
 with st.beta_expander("See explanation"):
     st.write(
diff --git a/lib/streamlit/delta_generator.py b/lib/streamlit/delta_generator.py
--- a/lib/streamlit/delta_generator.py
+++ b/lib/streamlit/delta_generator.py
@@ -614,7 +614,7 @@ def beta_expander(self, label=None, expanded=False) -> "DeltaGenerator":
         ...     st.image("https://static.streamlit.io/examples/dice.jpg")
 
         .. output ::
-            https://static.streamlit.io/0.66.0-2BLtg/index.html?id=LzfUAiT1eM9Xy8EDMRkWyF
+            https://static.streamlit.io/0.66.0-2BLtg/index.html?id=7v2tgefVbW278gemvYrRny
             height: 750px
 
         """
diff --git a/lib/streamlit/elements/altair.py b/lib/streamlit/elements/altair.py
--- a/lib/streamlit/elements/altair.py
+++ b/lib/streamlit/elements/altair.py
@@ -12,7 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-"""A Python wrapper around Altair."""
+"""A Python wrapper around Altair.
+Altair is a Python visualization library based on Vega-Lite,
+a nice JSON schema for expressing graphs and charts."""
 
 from datetime import date
 
@@ -156,7 +158,7 @@ def bar_chart(dg, data=None, width=0, height=0, use_container_width=True):
         >>> st.bar_chart(chart_data)
 
         .. output::
-           https://static.streamlit.io/0.50.0-td2L/index.html?id=5U5bjR2b3jFwnJdDfSvuRk
+           https://static.streamlit.io/0.66.0-2BLtg/index.html?id=GaYDn6vxskvBUkBwsGVEaL
            height: 220px
 
         """
@@ -267,10 +269,16 @@ def generate_chart(chart_type, data, width=0, height=0):
     )
     y_scale = alt.Scale(type="utc") if _is_date_column(data, "value") else alt.Undefined
 
+    x_type = alt.Undefined
+    # Bar charts should have a discrete (ordinal) x-axis, UNLESS type is date/time
+    # https://github.com/streamlit/streamlit/pull/2097#issuecomment-714802475
+    if chart_type == "bar" and not _is_date_column(data, index_name):
+        x_type = "ordinal"
+
     chart = (
         getattr(alt.Chart(data, width=width, height=height), "mark_" + chart_type)()
         .encode(
-            alt.X(index_name, title="", scale=x_scale),
+            alt.X(index_name, title="", scale=x_scale, type=x_type),
             alt.Y("value", title="", scale=y_scale),
             alt.Color("variable", title="", type="nominal"),
             alt.Tooltip([index_name, "value", "variable"]),


Test patch: