问题
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:
- Execute my SQL queries
- Parse the returned data to the graphing library/module
- 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.
- 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
- Data URI's
- 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
- Line chart
- Column chart
- Bar chart
- Candlestick charts
- Pie chart
- Line chart
- Column chart
- Bar chart
- Pie chart
- 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