Displaying graphs/charts in Django [closed]

不问归期 提交于 2020-07-16 16:00:12

问题


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


回答1:


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]




回答2:


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:

  • http://www.highcharts.com
  • http://www.jqplot.com



回答3:


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




回答4:


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/



来源:https://stackoverflow.com/questions/5631247/displaying-graphs-charts-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!