File size: 752 Bytes
010071f
b8b8eab
010071f
b8b8eab
 
 
 
 
010071f
b8b8eab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pandas as pd
import plotly.graph_objects as go

def plot_sales_tool(file_path: str, date_col: str = "Month") -> str:
    """
    Builds an interactive Plotly line chart for Sales.
    Saves a PNG fallback (sales_plot.png) for Streamlit thumbnail.
    """
    df = pd.read_csv(file_path)

    if date_col not in df.columns or "Sales" not in df.columns:
        return f"❌ '{date_col}' or 'Sales' column missing."

    fig = go.Figure(
        go.Scatter(
            x=df[date_col],
            y=df["Sales"],
            mode="lines+markers",
            line=dict(width=2),
        )
    )
    fig.update_layout(title="Sales Trend", template="plotly_dark")
    fig.write_image("sales_plot.png")  # still save for PNG fallback

    return fig