BizIntel_AI / tools /plot_generator.py
mgbam's picture
Update tools/plot_generator.py
b8b8eab verified
raw
history blame
752 Bytes
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