Admin Chart
Admin Chart
html' %}
{% load static %}
{% block content %}
<style>
/* Custom CSS */
.chart-container {
border: 1px solid #dee2e6; /* Gray border */
border-radius: 5px; /* Rounded corners */
padding: 20px; /* Padding around the chart */
background-color: #fff; /* White background color */
margin-top: 20px; /* Add margin to separate from title */
}
.chart-container h2 {
color: #343a40; /* Dark text color */
margin-bottom: 20px; /* Bottom margin for heading */
}
// JavaScript code for handling dropdown selection and applying filters for year-
wise chart
document.getElementById('apply-year-filter-btn').addEventListener('click',
function() {
var selectedYear = document.getElementById('year-dropdown-year-chart').value;
updateYearlyCollectionTitle(selectedYear); // Update yearly collection title
window.location.href = '/dashboard/admin_chart/?year_for_year_chart=' +
selectedYear;
});
fig = go.Figure()
return plot_div
# Group data by month and sum the amounts for each month
monthly_collection = {}
for donation in data:
month_year_key = donation.service_date.strftime('%B-%Y')
if month_year_key not in monthly_collection:
monthly_collection[month_year_key] = 0
monthly_collection[month_year_key] += donation.amount
fig = go.Figure()
# Update layout
if selected_year is not None:
title = f'Monthly Collection for {selected_year}'
else:
current_year = datetime.now().year
title = f'Monthly Collection for {current_year}'
fig.update_layout(
title=title,
xaxis_title='Month',
yaxis_title='Amount',
template='plotly_white',
font=dict(family='Arial, sans-serif', size=12, color='#333'), # Darker
font color
margin=dict(l=60, r=60, t=80, b=60), # Increased margins
plot_bgcolor='#f5f5f5', # Light gray background color
paper_bgcolor='#f5f5f5', # Light gray paper background color
xaxis=dict(
showline=True,
showgrid=False,
showticklabels=True,
linecolor='#333',
linewidth=1,
ticks='outside',
tickfont=dict(family='Arial, sans-serif', size=10, color='#333'), #
Darker axis line and ticks
categoryorder='array', # Specify ordering for categorical axis
categoryarray=ordered_months # Order the months according to the
predefined list
),
yaxis=dict(
showline=True,
showgrid=True,
showticklabels=True,
linecolor='#333',
linewidth=1,
ticks='outside',
tickfont=dict(family='Arial, sans-serif', size=10, color='#333') #
Darker axis line and ticks
),
)
@user_passes_test(lambda u: is_administrator(u))
@csrf_exempt
@login_required
def admin_chart(request):
current_month = datetime.now().month
current_year = datetime.now().year
context = {
'month_chart_div': month_chart_div,
'year_chart_div': year_chart_div,
'months': [(i, calendar.month_name[i]) for i in range(1, 13)],
'years': sorted(years),
'years_for_year_chart': years_for_year_chart,
'selected_month': selected_month,
'selected_year': selected_year,
'selected_year_for_year_chart': selected_year_for_year_chart,# Provide
default value
'month_title': month_title, # Add the month title to the context
'year_title': year_title, # Add the year title to the context