diff --git a/statistiques/charts.py b/statistiques/charts.py index d6d2922..4025283 100644 --- a/statistiques/charts.py +++ b/statistiques/charts.py @@ -128,13 +128,18 @@ class ColumnWrapper(gchart.ColumnChart): options = { 'is3D': False, 'legend': {'position': 'labeled', 'maxLines': 3, 'textStyle': {'fontSize': 16, }}, - 'title': 'test', } def __init__(self, *args, **kwargs): - kwargs.update(options=self.options.copy()) + kwargs.update(self.options.copy()) super().__init__(*args, **kwargs) + def get_js_template(self): + return "statistiques/gchart/column_chart.html" + + def get_html_template(self): + return "statistiques/gchart/html.html" + class DonneeGeneraleChart(gchart.BarChart): @@ -229,7 +234,7 @@ class RencontreParSujetChart(PieWrapper): ) -class RencontreParMoisChart(gchart.ColumnChart): +class RencontreParMoisChart(ColumnWrapper): def __init__(self, queryset): data = [("Mois", "Rencontres")] @@ -244,6 +249,7 @@ class RencontreParMoisChart(gchart.ColumnChart): data += [(NOM_MOIS[item['mois']], item['nbr']) for item in par_mois] else: data += [("Mois", 0)] + super().__init__(SimpleDataSource(data), options={ "title": "Nombre de rencontres par mois" diff --git a/statistiques/templates/statistiques/gchart/column_chart.html b/statistiques/templates/statistiques/gchart/column_chart.html new file mode 100644 index 0000000..476c42a --- /dev/null +++ b/statistiques/templates/statistiques/gchart/column_chart.html @@ -0,0 +1,20 @@ + {% extends "graphos/gchart/base.html" %} + +{% block create_chart %} + var chart_data = data; + var chart_div = document.getElementById('{{ chart.get_html_id }}'); + var chart = new google.visualization.ColumnChart(chart_div); + + var data = new google.visualization.DataView(chart_data); + data.setColumns([0, 1, + { calc: "stringify", + sourceColumn: 1, + type: "string", + role: "annotation" }, + ]); + + // Wait for the chart to finish drawing before calling the getImageURI() method. + google.visualization.events.addListener(chart, 'ready', function () { + $("#image-{{ chart.get_html_id }}").attr("href", chart.getImageURI()); + }); +{% endblock %}