The Powerless Pointless Presentation

Technology has made it possible for Machines to learn by themselves. But have humans learnt to learn? The way education system in India is managed reminds me of the moment at the beginning of an…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to integrate Highcharts.js with Django?

Highcharts is a open-source javascript library that helps you to work with data visualization and charts. Highcharts provide different types of charts like pie chart, line charts, area charts, column and bar charts, Scatter and bubble charts and many more for data visualization. In this tutorial you are going to learn how to integrate Highcharts with Django.

You can either download and serve it locally or you can use Highcharts CDN.

You can add following script in case you want more features for charts like view in full screen, print chart and download chart in png image, jpeg image, pdf document and svg vector image.

The basic structure for chart is:

The most straightforward way to use highcharts is by writing directly in the template but it is not recommended.

views.py

analytics.html

The result is the following chart.

In the above chart, we send the static data in templates for chart configuration. For the dynamic data, it will be better to do all the chart configuration in the backend (run through the queryset, create a separate data and append the values and do the formatting in views). After that we can

Here you will learn chart configuration with dynamic data using ajax method.

We will be using Staff dataset for data.

Views.py

analytics.html

We added a div with id container and data-url to access url for sending ajax request. When we get the success response from ajax request, we added the response data on Highcharts which will add the resulted chart on scection with id container. The result is the following screen shot.

In this tutorial we learned the basics of how to integrate Highcharts with Django. We can also use other charts on a similar way and configure title, color, nameing etc.

While communicating Django with Highcharts.js always prefer returning data or whole chart configuration as JSON objects.

Add a comment

Related posts:

Great 82 Books I Would Recommend You To Read

Before I read these books, I had read some reviews which had me wondering if this one would be something I’d like, reviews from people whose opinions I trust. It’s True, so the book stayed on my “TBR…

Bourdain

Meals were always a multilayered sustenance in my childhood home — a sustenance for the pallet, body, heart, and the part of my brain that holds memories I access whenever I need to remember why I’m…

What is a Convertible Note and How does it work?

Speed and simplicity are key in early-stage startups, as is access to capital. Convertible notes can be a fast, straightforward way for founders to raise money during the early stages of their…