¿Alguien tiene idea de cómo agregar un gráfico alto en view.py? lo que significa que mis datos se filtran en función del código de Python y del marco de datos se convierten en gráfico alto.
Instale django-highcharts usando pip (recomendamos hacerlo en un virtualenv).
git clone https://github.com/novapost/django-highcharts.git cd django-highcharts pip install -e ./Para integrarlo en un proyecto de Django, simplemente agréguelo a sus INSTALLED_APPS:
INSTALLED_APPS = [ # some interesting stuff... 'highcharts', # some other stuff... ]No olvide configurar su ruta STATIC_ROOT y ejecutar el siguiente comando para actualizar los archivos estáticos:
python manage.py collectstaticvista
from highcharts.views import HighChartsBarView class BarView(HighChartsBarView): categories = ['Orange', 'Bananas', 'Apples'] @property def series(self): result = [] for name in ('Joe', 'Jack', 'William', 'Averell'): data = [] for x in range(len(self.categories)): data.append(random.randint(0, 10)) result.append({'name': name, "data": data}) return resultmodelo
{% load staticfiles %}<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Hello</title> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript" src="{% static 'js/highcharts/highcharts.js' %}"></script> <script type="text/javascript"> $(function () { $.getJSON("{% url 'bar' %}", function(data) { $('#container').highcharts(data); }); }); </script> </head> <body> <div id="container" style="height: 300px"></div> </body> </html>Tenga en cuenta que el archivo highcharts.js debe llamarse después de la biblioteca JQuery.
Mire la Documentación PDF para más detalles.
EDITAR 1
Instale el paquete usando pip
pip install pandas-highchartsImportarlo en tus vistas
import pandas_highcharts df = ... # create your dataframe here chart = pandas_highcharts.serialize(df, render_to='my-chart', output_type='json')en tus plantillas
<div id="my-chart"></div> <script type="text/javascript"> new Highcharts.Chart({{chart|safe}}); </script>