import pandas as pd
import plotly.express as px

# Load the dataset
file_path = 'C:\\Users\\loydt\\Downloads\\Superstore Sales Dataset.csv'
data = pd.read_csv(file_path)

# Convert 'Order Date' to a datetime format
data['Order Date'] = pd.to_datetime(data['Order Date'], format='%d/%m/%Y',
errors='coerce')

# Set the 'Order Date' as the index and resample by month to sum up sales for each month
data.set_index('Order Date', inplace=True)

# Resample by month and sum the sales
monthly_sales = data.resample('ME').agg({'Sales': 'sum'}).reset_index()

# Create a line plot for Sales vs. Order Date (monthly aggregated)
fig3 = px.line(monthly_sales, x='Order Date', y='Sales', title='Monthly Sales Trend')

# Add scatter plot (dots) to each data point
fig3.add_scatter(x=monthly_sales['Order Date'], y=monthly_sales['Sales'], mode='markers', 
                 marker=dict(color='lightblue', size=8, line=dict(width=2, color='blue')))

# Customize the line plot's appearance
fig3.update_traces(line_color='white', line_width=2)  # Change line color to light blue

# Update layout settings for the plot
fig3.update_layout(
    xaxis_title='Order Date',
    yaxis_title='Sales',
    title='Monthly Sales Trend',
    xaxis_title_font=dict(size=14),
    yaxis_title_font=dict(size=14),
    title_font=dict(size=18),
    xaxis_showgrid=True,
    yaxis_showgrid=True,
    xaxis_gridcolor='gray',
    yaxis_gridcolor='gray',

    # Set the background color to a darker shade
    paper_bgcolor='rgba(45, 45, 45, 1)',  # Background outside the plot area
    plot_bgcolor='rgba(40, 40, 40, 1)',   # Background inside the plot area

    # Font color for readability
    font=dict(color='white')
)

# Show the plot
fig3.show()