函數簽名
st.metric(label, value, delta=None, delta_color="normal")
參數 | 說明 |
---|---|
label (str) | 指標的標題或標題 |
value (int, float, str, or None) | 指標的值。 None 被呈現為長破折號。 |
delta (int, float, str, or None) | 指標如何變化的指標,在指標下方用箭頭表示。如果 delta 為負數 (int/float) 或以減號 (str) 開頭,則箭頭指向下方且文本為紅色;否則箭頭指向上方,文本為綠色。如果無(默認),則不顯示增量指示器。 |
delta_color (str) | 如果"normal"(默認),則增量指示器如上文所述顯示。如果"inverse",正時為紅色,負時為綠色。當負麵變化被認為是好的時,這很有用,例如如果成本降低。如果"off",delta 顯示為灰色,無論其值如何。 |
示例
st.metric(label="Temperature", value="70 °F", delta="1.2 °F")
st.metric結合在一起看起來特別好st.columns:
col1, col2, col3 = st.columns(3)
col1.metric("Temperature", "70 °F", "1.2 °F")
col2.metric("Wind", "9 mph", "-8%")
col3.metric("Humidity", "86%", "4%")
增量指示器顏色也可以反轉或關閉:
st.metric(label="Gas price", value=4, delta=-0.5,
delta_color="inverse")
st.metric(label="Active developers", value=123, delta=123,
delta_color="off")
相關用法
- Python Streamlit st.markdown用法及代碼示例
- Python Streamlit st.map用法及代碼示例
- Python Streamlit st.multiselect用法及代碼示例
- Python Streamlit st.experimental_singleton.clear用法及代碼示例
- Python Streamlit st.bokeh_chart用法及代碼示例
- Python Streamlit st.caption用法及代碼示例
- Python Streamlit st.text_input用法及代碼示例
- Python Streamlit st.area_chart用法及代碼示例
- Python Streamlit st.title用法及代碼示例
- Python Streamlit st.cache用法及代碼示例
- Python Streamlit st.experimental_singleton用法及代碼示例
- Python Streamlit st.empty用法及代碼示例
- Python Streamlit st.error用法及代碼示例
- Python Streamlit st.video用法及代碼示例
- Python Streamlit st.vega_lite_chart用法及代碼示例
- Python Streamlit st.slider用法及代碼示例
- Python Streamlit st.header用法及代碼示例
- Python Streamlit st.container用法及代碼示例
- Python Streamlit st.form_submit_button用法及代碼示例
- Python Streamlit st.form用法及代碼示例
- Python Streamlit st.plotly_chart用法及代碼示例
- Python Streamlit st.bar_chart用法及代碼示例
- Python Streamlit st.code用法及代碼示例
- Python Streamlit st.experimental_memo.clear用法及代碼示例
- Python Streamlit st.warning用法及代碼示例
注:本文由純淨天空篩選整理自streamlit.io大神的英文原創作品 st.metric。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。