import streamlit as st
import pandas as pd
import plotly.express as px
import io
# Page configuration
st.set_page_config(
page_title="Excel Graph Generator",
page_icon="📈",
layout="wide"
)
# Style input fields with black text and Times New Roman
st.markdown("""
""", unsafe_allow_html=True)
# Title and description
st.title('📊 Excel Graph Generator')
st.write('Upload your Excel file and create customized graphs with ease!')
# File upload
uploaded_file = st.file_uploader("Upload Excel File", type=['xlsx', 'xls'])
if uploaded_file:
# Read Excel file
df = pd.read_excel(uploaded_file)
# Show data preview
st.subheader("Data Preview")
st.dataframe(df.head())
# Column selection
st.subheader("Select Data for Plotting")
x_column = st.selectbox("Select X-axis column (Date)", df.columns)
y_columns = st.multiselect("Select Y-axis column(s)", [col for col in df.columns if col != x_column])
if y_columns:
# Graph customization
st.subheader("Customize Your Graph")
# Basic settings
plot_title = st.text_input("Enter Plot Title", "My Custom Graph")
x_axis_label = st.text_input("X-axis Label", x_column)
y_axis_label = st.text_input("Y-axis Label", "Values")
# Font size customization
st.subheader("Font Size Customization")
title_font_size = st.slider("Title Font Size", 10, 40, 20)
axis_label_font_size = st.slider("Axis Label Font Size", 8, 30, 14)
tick_font_size = st.slider("Tick Label Font Size", 8, 24, 10)
legend_font_size = st.slider("Legend Font Size", 8, 24, 12)
# Legend position controls
st.subheader("Legend Position Control")
col1, col2 = st.columns(2)
with col1:
legend_x = st.slider("Legend X Position", -0.5, 2.0, 1.05, 0.05)
with col2:
legend_y = st.slider("Legend Y Position", -0.5, 2.0, 1.0, 0.05)
# Define vibrant colors
default_colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEEAD',
'#FF9F1C', '#E71D36', '#2EC4B6', '#011627']
# Color customization
st.subheader("Color Customization")
use_custom_colors = st.checkbox("Use custom colors for lines")
custom_colors = {}
if use_custom_colors:
for i, col in enumerate(y_columns):
default_color = default_colors[i % len(default_colors)]
custom_colors[col] = st.color_picker(f"Color for {col}", default_color)
# Legend customization
st.subheader("Customize Legend Names")
legend_names = {}
for col in y_columns:
legend_names[col] = st.text_input(f"Legend name for {col}", col)
# Generate plot
if st.button("Generate Graph"):
# Convert date column to datetime
df[x_column] = pd.to_datetime(df[x_column])
# Choose colors based on user selection
if use_custom_colors:
colors_to_use = [custom_colors[col] for col in y_columns]
else:
colors_to_use = default_colors[:len(y_columns)]
# Create figure with selected colors
fig = px.line(df, x=x_column, y=y_columns,
color_discrete_sequence=colors_to_use)
# Update legend names and hover template with date and time
for i, trace in enumerate(fig.data):
trace.name = legend_names[y_columns[i]]
trace.hovertemplate = f"{legend_names[y_columns[i]]}: %{{y}}
{x_axis_label}: %{{x|%d-%m-%Y %H:%M:%S}}"
# Layout updates with Times New Roman and black text
fig.update_layout(
title=dict(
text=plot_title,
x=0.5,
xanchor='center',
yanchor='top',
font=dict(family="Times New Roman", color="black", size=title_font_size)
),
showlegend=True,
legend=dict(
orientation="v",
yanchor="top",
y=legend_y,
xanchor="right",
x=legend_x,
bgcolor="white",
bordercolor="Black",
borderwidth=1,
font=dict(family="Times New Roman", color="black", size=legend_font_size),
title=dict(text="")
),
hovermode='x unified',
plot_bgcolor='white',
paper_bgcolor='white',
xaxis=dict(
showgrid=True,
gridwidth=1,
gridcolor='LightGray',
showline=True,
linewidth=1,
linecolor='black',
mirror=True,
tickangle=-90,
title_text=x_axis_label,
title_font=dict(family="Times New Roman", color="black", size=axis_label_font_size),
tickfont=dict(family="Times New Roman", color="black", size=tick_font_size),
type='date',
tickformat='%d-%m-%Y',
dtick='D1',
tickmode='linear'
),
yaxis=dict(
showgrid=True,
gridwidth=1,
gridcolor='LightGray',
showline=True,
linewidth=1,
linecolor='black',
mirror=True,
title_text=y_axis_label,
title_font=dict(family="Times New Roman", color="black", size=axis_label_font_size),
tickfont=dict(family="Times New Roman", color="black", size=tick_font_size)
),
margin=dict(l=80, r=150, t=100, b=100),
width=900,
height=600,
shapes=[
dict(
type='rect',
xref='paper',
yref='paper',
x0=0,
y0=0,
x1=1,
y1=1,
line=dict(
color='black',
width=2,
)
)
],
font=dict(family="Times New Roman")
)
# Display plot
st.plotly_chart(fig, use_container_width=True)
# Download options
buffer = io.StringIO()
fig.write_html(buffer)
st.download_button(
label="📊 Download Plot",
data=buffer.getvalue(),
file_name="plot.html",
mime="text/html"
)
# Footer
st.markdown("---")
st.markdown("""
### 📝 Features:
- Excel file upload and preview
- Times New Roman font throughout
- Black text for all elements
- Clean legend display with custom names
- Customizable plot title, axes labels, and legend names
- Custom color selection for each line
- Adjustable font sizes for all text elements
- Interactive legend positioning with precise controls
- Interactive plot with hover details
- Download options in HTML format
"""
"""
### 📝 For Support And Assistance:
Contact:
- Harshitha Gunnam
gunnamharshitha2@gmail.com
- Varun Ravichander
varunravichander2007@gmail.com
""")