File size: 8,141 Bytes
a34273f
 
 
 
 
 
 
 
 
 
 
 
 
 
405fcf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a34273f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec94869
a34273f
 
 
 
 
 
 
 
 
 
 
405fcf9
 
 
 
 
 
 
a34273f
 
 
 
 
 
 
 
405fcf9
 
 
 
 
 
 
 
 
 
 
 
 
 
a34273f
 
 
 
 
 
 
 
9ca3cab
 
a34273f
405fcf9
 
 
 
 
 
 
a34273f
405fcf9
a34273f
5806ec4
a34273f
 
5806ec4
a34273f
 
 
 
 
 
 
 
405fcf9
a34273f
 
 
 
 
 
 
 
 
 
 
405fcf9
a34273f
 
 
 
 
 
 
 
 
 
 
 
 
9ca3cab
a34273f
405fcf9
 
9ca3cab
5806ec4
 
 
a34273f
 
 
 
 
 
 
 
 
 
405fcf9
 
a34273f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5806ec4
 
 
a34273f
 
405fcf9
 
a34273f
 
 
 
 
 
 
 
405fcf9
a34273f
405fcf9
9ca3cab
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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("""
<style>
* {
    font-family: 'Times New Roman', Times, serif !important;
}
.stTextInput input {
    color: black !important;
    font-family: 'Times New Roman', Times, serif !important;
}
.stSelectbox select {
    color: black !important;
    font-family: 'Times New Roman', Times, serif !important;
}
.stMultiSelect select {
    color: black !important;
    font-family: 'Times New Roman', Times, serif !important;
}
</style>
""", 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}}<br>{x_axis_label}: %{{x|%d-%m-%Y %H:%M:%S}}<extra></extra>"
            
            # 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
""")