Displaying graphs/charts in Django

Question:

I’m making a report app in Django that involves plenty of graphs and charts.

Is there an easy graphing library/module that allows me to achieve this workflow:

  1. Execute my SQL queries
  2. Parse the returned data to the graphing library/module
  3. Graphing library/module manipulates the data into a chart/graph which I can output to a Django template easily.

I’ve spent the last couple of days playing around with Matplotlib and Django. There are seemingly only a few ways to get the graphs to render in Django.

  1. Use 2 views, one to render the PNG and the other one to output the HTML with the img src pointing to the first view. Link
  2. Data URI’s
  3. Write the image to file and then call it with the view

Is there anyway I can do this more easily?

Thanks

Asked By: super9

||

Answers:

One lighter alternative is pycha

See this blogpost to get an idea: A quick post on using Python Charts to generate nice SVG charts for your django website

Another option is to include google charts
in your templates.

If rendering the graph via js in your templates is an option, these
are two popular libraries:

Answered By: arie

You might want to look at

Django Graphos

It supports lot of backends, and integrates well with Django orm, but can work with other data sources too.

Chart types supported

Flot

  • Line chart
  • Bar Chart
  • Point Chart

Google Charts

  • Line chart
  • Column chart
  • Bar chart
  • Candlestick charts
  • Pie chart

YUI

  • Line chart
  • Column chart
  • Bar chart
  • Pie chart

Morris.js

  • Line chart
  • Column chart
  • Donut chart

[Disclosure: I am one of the authors]

Answered By: shabda

Take a look at these well know libraries which will come handy to plot graphs without ever writing JS

Chartit: http://django-chartit.mrsenko.com/demo/chart/basic-line/

ChartJs: https://github.com/novafloss/django-chartjs

Django charts: http://www.fusioncharts.com/django-charts/

Django nvd3: https://github.com/areski/django-nvd3

Django graphos: http://agiliq.com/demo/graphos/

Django Gcharts: https://github.com/rhblind/django-gcharts

Answered By: naren

All the Django modules for displaying graphs take a lot of configuration and setup. However I found one solution with only one dependency: the Python library Django

You can make all your plots in Python and export them into HTML format to include in your Django output.

Look at this article for an example: http://www.codingwithricky.com/2019/08/28/easy-django-plotly/

Answered By: ribab
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.