| 
 | 1 | +"""Example of displaying a sine wave using streamlit-echarts in a nipanel."""  | 
 | 2 | + | 
 | 3 | +import streamlit as st  | 
 | 4 | +from streamlit_echarts import st_echarts  | 
 | 5 | + | 
 | 6 | +from nipanel import initialize_panel  | 
 | 7 | + | 
 | 8 | + | 
 | 9 | +st.set_page_config(page_title="Simple Graph Example", page_icon="📈", layout="wide")  | 
 | 10 | +st.title("Simple Sine Wave Visualization")  | 
 | 11 | + | 
 | 12 | +panel = initialize_panel()  | 
 | 13 | +time_points = panel.get_value("time_points", [0.0])  | 
 | 14 | +sine_values = panel.get_value("sine_values", [0.0])  | 
 | 15 | +amplitude = panel.get_value("amplitude", 1.0)  | 
 | 16 | +frequency = panel.get_value("frequency", 1.0)  | 
 | 17 | + | 
 | 18 | +col1, col2, col3, col4, col5 = st.columns(5)  | 
 | 19 | +with col1:  | 
 | 20 | +    st.metric("Amplitude", f"{amplitude:.2f}")  | 
 | 21 | +with col2:  | 
 | 22 | +    st.metric("Frequency", f"{frequency:.2f} Hz")  | 
 | 23 | +with col3:  | 
 | 24 | +    st.metric("Min Value", f"{min(sine_values):.3f}")  | 
 | 25 | +with col4:  | 
 | 26 | +    st.metric("Max Value", f"{max(sine_values):.3f}")  | 
 | 27 | +with col5:  | 
 | 28 | +    st.metric("Data Points", len(sine_values))  | 
 | 29 | + | 
 | 30 | +# Prepare data for echarts  | 
 | 31 | +data = [{"value": [x, y]} for x, y in zip(time_points, sine_values)]  | 
 | 32 | + | 
 | 33 | +# Configure the chart options  | 
 | 34 | +options = {  | 
 | 35 | +    "animation": False,  # Disable animation for smoother updates  | 
 | 36 | +    "title": {"text": "Sine Wave"},  | 
 | 37 | +    "tooltip": {"trigger": "axis"},  | 
 | 38 | +    "xAxis": {"type": "value", "name": "Time (s)", "nameLocation": "middle", "nameGap": 30},  | 
 | 39 | +    "yAxis": {  | 
 | 40 | +        "type": "value",  | 
 | 41 | +        "name": "Amplitude",  | 
 | 42 | +        "nameLocation": "middle",  | 
 | 43 | +        "nameGap": 30,  | 
 | 44 | +    },  | 
 | 45 | +    "series": [  | 
 | 46 | +        {  | 
 | 47 | +            "data": data,  | 
 | 48 | +            "type": "line",  | 
 | 49 | +            "showSymbol": True,  | 
 | 50 | +            "smooth": True,  | 
 | 51 | +            "lineStyle": {"width": 2, "color": "#1f77b4"},  | 
 | 52 | +            "areaStyle": {"color": "#1f77b4", "opacity": 0.3},  | 
 | 53 | +            "name": "Sine Wave",  | 
 | 54 | +        }  | 
 | 55 | +    ],  | 
 | 56 | +}  | 
 | 57 | + | 
 | 58 | +# Display the chart  | 
 | 59 | +st_echarts(options=options, height="400px")  | 
0 commit comments