score:2

install django-highcharts using pip (we do recommend to do it in a virtualenv).

git clone https://github.com/novapost/django-highcharts.git
cd django-highcharts
pip install -e ./

to integrate it into a django project, simply add it to your installed_apps:

installed_apps = [
# some interesting stuff...
'highcharts',
# some other stuff...
]

don’t forget to set your static_root path and to run the following command to update the static files:

python manage.py collectstatic

view

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 result

template

{% 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>

please note that the highcharts.js file should be called after the jquery library.

look into documentation pdf for details.

edit 1

install the package using pip

pip install pandas-highcharts

import it in your views

import pandas_highcharts
df = ... # create your dataframe here
chart = pandas_highcharts.serialize(df, render_to='my-chart', output_type='json')

n your templates

<div id="my-chart"></div>
<script type="text/javascript">
  new highcharts.chart({{chart|safe}});
</script>

Related Query

More Query from same tag