Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Build Interactive Analytical Dashboard in Django
Vishwas R
Vishwas R

Posted on • Edited on

     

Build Interactive Analytical Dashboard in Django

Django is a powerful Python Web Framework that makes building web applications and dashboards a breeze. There are open-source dashboards built with Django that come with modern UI Kits, and developers can create analytic dashboards in a Django app. In this article, let's explore how to build a beautiful dashboard in Django using Bootstrap,CanvasJS Python Charts and a few other tools.

Django Dashboard using CanvasJS Python Charts

Project Setup

Create a new Django project. And create a new app within the project.

django-admin startproject dashboardpython manage.py startapp charts
Enter fullscreen modeExit fullscreen mode

Create View

Create a new file in the charts app called views.py. In this file, we'll define the view that will render our dashboard. Here's an example view that renders a template called index.html

from django.shortcuts import renderdef dashboard(request):    return render(request, 'index.html')
Enter fullscreen modeExit fullscreen mode

Create Template

Create a new file in the charts/templates directory called dashboard.html. Define the layout of the dashboard using Bootstrap.

<div>    <div>        <nav>            <!-- Sidebar content goes here -->        </nav>        <main>            <!-- Main content goes here -->        </main>    </div></div>
Enter fullscreen modeExit fullscreen mode

Add Charts to the Dashboard

CanvasJS is a powerful charting library that lets you create interactive charts for dashboards. To add CanvasJS charts to the project, download the library and include it in the template.

  • Download the library from CanvasJS website.
  • Extract the files to 'charts/static' folder.
  • Include canvasjs.min.js in the template.
<script src="{% static canvasjs.min.js' %}"></script>
Enter fullscreen modeExit fullscreen mode

Create Charts

Now, that CanvasJS is included in the template, you can start creating different of charts like line, column, pie, etc. to show them in the dashboard.

/* index.html */<div></div><script>    window.onload = function () {        var chart = new CanvasJS.Chart("chartContainer", {            title:{                text: "Column Chart"            },            data: [{                dataPoints: {{ datapoints | safe }}        });        chart.render();    }</script>
Enter fullscreen modeExit fullscreen mode

Update the view to return the data for the chart.

/* views.py */from django.http import HttpResponsefrom django.shortcuts import renderfrom django.template import loaderdef index(request):    datapoints= [        { "label": "Jan", "y": 10000 },        { "label": "Feb", "y": 30162 },        { "label": "Mar", "y": 26263 },        { "label": "Apr", "y": 18394 },        { "label": "May", "y": 18287 },        { "label": "Jun", "y": 28682 },        { "label": "Jul", "y": 31274 },        { "label": "Aug", "y": 33259 },        { "label": "Sep", "y": 25849 },        { "label": "Oct", "y": 24159 },        { "label": "Nov", "y": 32651 },        { "label": "Dec", "y": 31984 }    ]    return render(request, 'index.html', { "datapoints" : datapoints })
Enter fullscreen modeExit fullscreen mode

Customize the Dashboard

Now that you have added one chart to the dashboard, add few more charts and customize the look and feel of the charts to match your dashboard. You can change the color & font-family of all the textual content of the chart to match it with the theme of dashboard.

Github Link:https://github.com/vishwas-r/Django-Dashboard-using-CanvasJS-Python-Charts

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

#Engineer || #SoftwareDeveloper || #Techie || #Cricketer || #Traveler || #Blogger
  • Location
    Bengaluru
  • Work
    Lead Developer at Fenopix
  • Joined

More fromVishwas R

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp