This project demonstrates a simple dashboard with three charts (Line, Bar, Pie) that fetch data from a Django API backend and display them using a Next.js frontend. The charts are dynamically populated based on the backend API responses and are responsive across different screen sizes.
my-dashboard/
├── backend/ # Django API for serving chart data
├── frontend/ # Next.js Frontend for displaying the dashboard
- Backend: Python 3.9.7, pip
- Frontend: Node.js 22.7 + and npm (or yarn)
-
Navigate to the
backend
directory:cd backend
-
Create and activate a virtual environment
python -m venv env source env/bin/activate
-
Install dependencies
pip install django djangorestframework django-cors-headers
- Apply migrations to set up the database
python manage.py migrate
- Run the Django development server
python manage.py runserver
- Navigate to the frontend directory:
cd frontend
- Install dependencies
npm install
- Run the Next.js development server
npm run dev
The frontend will run at http://localhost:3000.
Django: A Python-based web framework for the API backend.
Django REST Framework: For creating API endpoints.
CORS Headers: To handle cross-origin requests from the frontend.
Next.js: A React-based framework for the frontend.
axios: For making HTTP requests to the backend API.
react-chartjs-2: A React wrapper for Chart.js for visualizing data.
The approach was to create a well-organized and simple dashboard application, with a Django backend serving the chart data and a Next.js frontend displaying the charts. The Django REST API provides data for the charts in JSON format, which is consumed by the Next.js frontend using axios. Chart.js, wrapped with react-chartjs-2, is used to render the charts.
Key considerations:
Backend: Easy-to-extend Django API that provides the necessary chart data.
Frontend: Clean, responsive UI using Next.js and Chart.js.
Scalability: The project is structured to be scalable and maintainable, allowing future additions of new features or charts.
To run both the Django backend and Next.js frontend at the same time, open two terminal windows:
- In the first terminal, start the Django backend
cd backend
python manage.py runserver
- In the second terminal, start the Next.js frontend
cd frontend
npm run dev
Visit http://localhost:3000/dashboard in your browser to access the application.