Skip to content

Commit 0ee6019

Browse files
committed
visualize your data using django-excel
1 parent 499d60a commit 0ee6019

File tree

11 files changed

+91
-14
lines changed

11 files changed

+91
-14
lines changed

.moban.d/docs/source/index.rst.jj2

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ exported as a single sheet file.
197197
Render an excel-alike html in a browser
198198
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
199199

200-
In the tutorial, you have seen the rendering of the excel-alike table. First of
200+
In previous section, you have seen the rendering of the excel-alike table. First of
201201
all, the credits goes to `handsontable developers <https://handsontable.com/>`_.
202-
`pyexcel-handsontable` as renderer plugin to pyexcel v0.5.0 bring it to
202+
`pyexcel-handsontable`_ as renderer plugin to pyexcel v0.5.0 bring it to
203203
pyexcel developers.
204204

205205
Here is how it is done. Simply put in 'handsontable.html' instead of 'xls' as
@@ -299,6 +299,29 @@ set exported as a single sheet file as:
299299
.. image:: custom-export.png
300300

301301

302+
Visualize your data
303+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
304+
305+
Let's go to the admin page and update some votes for the choices.
306+
307+
.. image:: admin-vote.png
308+
309+
In my case, I have updated all of them and have gotten something like this:
310+
311+
.. image:: votes-handson-table.png
312+
313+
Now, let's look at the survey result(http://localhost:8000/polls/survey_result/)
314+
for "What's your favorite IDE?":
315+
316+
.. image:: survey-result.png
317+
318+
`pyexcel-pygal`_ provide you the common data visualization capability to show
319+
your data intuitively. Here is the code to achieve that:
320+
321+
.. literalinclude:: ../../polls/views.py
322+
:lines: 192-217
323+
324+
302325
{%endblock%}
303326

304327
{%block api_table%}

.moban.d/tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pyexcel-ods3>=0.1.0
55
pyexcel-xls>=0.1.0
66
pyexcel-xlsx>=0.1.0
77
pyexcel-handsontable
8+
pyexcel-pygal
89
{%endblock%}

README.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ django-excel - Let you focus on data, instead of file formats
1111
.. image:: https://codecov.io/github/pyexcel/django-excel/coverage.png
1212
:target: https://codecov.io/github/pyexcel/django-excel
1313

14-
.. image:: https://img.shields.io/gitter/room/gitterHQ/gitter.svg
15-
:target: https://gitter.im/pyexcel/Lobby
16-
1714
.. image:: https://readthedocs.org/projects/django-excel/badge/?version=latest
1815
:target: http://django-excel.readthedocs.org/en/latest/
1916

@@ -79,12 +76,11 @@ The highlighted features are:
7976
`pyexcel-ods`_ ods `odfpy`_ same as above
8077
`pyexcel-odsr`_ ods(read only) lxml same as above
8178
`pyexcel-text`_ (write only)json, rst, `tabulate`_ 2.6, 2.7, 3.3, 3.4
82-
mediawiki, html, 3.5, 3.6, pypy
79+
mediawiki, html, 3.5, pypy, pypy3
8380
latex, grid, pipe,
8481
orgtbl, plain simple
8582
`pyexcel-handsontable`_ handsontable in html `handsontable`_ same as above
86-
`pyexcel-pygal`_ svg chart `pygal`_ 2.7, 3.3, 3.4, 3.5
87-
3.6, pypy
83+
`pyexcel-pygal`_ svg chart `pygal`_ same as above [#f3]_
8884
======================== ======================= =============== ==================
8985

9086
.. _pyexcel-io: https://github.com/pyexcel/pyexcel-io
@@ -111,6 +107,7 @@ The highlighted features are:
111107
.. _pyexcel-matplotlib: https://github.com/pyexcel/pyexcel-matplotlib
112108
.. _matplotlib: https://matplotlib.org
113109

110+
.. [#f3] coming soon
114111
115112
In order to manage the list of plugins installed, you need to use pip to add or remove
116113
a plugin. When you use virtualenv, you can have different plugins per virtual

doc/source/admin-vote.png

27.7 KB
Loading

doc/source/index.rst

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ The highlighted features are:
7171
`pyexcel-ods`_ ods `odfpy`_ same as above
7272
`pyexcel-odsr`_ ods(read only) lxml same as above
7373
`pyexcel-text`_ (write only)json, rst, `tabulate`_ 2.6, 2.7, 3.3, 3.4
74-
mediawiki, html, 3.5, 3.6, pypy
74+
mediawiki, html, 3.5, pypy, pypy3
7575
latex, grid, pipe,
7676
orgtbl, plain simple
7777
`pyexcel-handsontable`_ handsontable in html `handsontable`_ same as above
78-
`pyexcel-pygal`_ svg chart `pygal`_ 2.7, 3.3, 3.4, 3.5
79-
3.6, pypy
78+
`pyexcel-pygal`_ svg chart `pygal`_ same as above [#f3]_
8079
======================== ======================= =============== ==================
8180

8281
.. _pyexcel-io: https://github.com/pyexcel/pyexcel-io
@@ -103,6 +102,7 @@ The highlighted features are:
103102
.. _pyexcel-matplotlib: https://github.com/pyexcel/pyexcel-matplotlib
104103
.. _matplotlib: https://matplotlib.org
105104

105+
.. [#f3] coming soon
106106
107107
In order to manage the list of plugins installed, you need to use pip to add or remove
108108
a plugin. When you use virtualenv, you can have different plugins per virtual
@@ -377,9 +377,9 @@ exported as a single sheet file.
377377
Render an excel-alike html in a browser
378378
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
379379

380-
In the tutorial, you have seen the rendering of the excel-alike table. First of
380+
In previous section, you have seen the rendering of the excel-alike table. First of
381381
all, the credits goes to `handsontable developers <https://handsontable.com/>`_.
382-
`pyexcel-handsontable` as renderer plugin to pyexcel v0.5.0 bring it to
382+
`pyexcel-handsontable`_ as renderer plugin to pyexcel v0.5.0 bring it to
383383
pyexcel developers.
384384

385385
Here is how it is done. Simply put in 'handsontable.html' instead of 'xls' as
@@ -479,6 +479,25 @@ set exported as a single sheet file as:
479479
.. image:: custom-export.png
480480

481481

482+
Visualize your data
483+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
484+
485+
Let's go to the admin page and update some votes for the choices. In my case,
486+
I have got something like this:
487+
488+
.. image:: votes-handson-table.png
489+
490+
Now, let's look at the survey result for "What's your favorite IDE?":
491+
492+
.. image:: survey-result.png
493+
494+
`pyexcel-pygal`_ provide you the common data visualization capability to show
495+
your data intuitively. Here is the code to achieve that:
496+
497+
.. literalinclude:: ../../polls/views.py
498+
:lines: 192-212
499+
500+
482501
.. _data-types-and-its-conversion-funcs:
483502

484503
All supported data types

doc/source/survey-result.png

28.8 KB
Loading

doc/source/votes-handson-table.png

24.1 KB
Loading

polls/urls.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
views.embed_handson_table, name="embed_handson_view"),
2020
url(r'^embedded_handson_view_single/',
2121
views.embed_handson_table_from_a_single_table,
22-
name="embed_handson_view")
22+
name="embed_handson_view"),
23+
# survey_result
24+
url('^survey_result/',
25+
views.survey_result, name='survey_result'),
2326
]

polls/views.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,31 @@ def embed_handson_table_from_a_single_table(request):
187187
{
188188
'handsontable_content': content.read()
189189
})
190+
191+
192+
def survey_result(request):
193+
question = Question.objects.get(slug='ide')
194+
query_sets = Choice.objects.filter(question=question)
195+
column_names = ['choice_text', 'votes']
196+
197+
# Obtain a pyexcel sheet from the query sets
198+
sheet = excel.pe.get_sheet(query_sets=query_sets,
199+
column_names=column_names)
200+
sheet.name_columns_by_row(0)
201+
sheet.column.format('votes', int)
202+
203+
# Transform the sheet into an svg chart
204+
svg = excel.pe.save_as(
205+
array=[sheet.column['choice_text'], sheet.column['votes']],
206+
dest_file_type='svg',
207+
dest_chart_type='pie',
208+
dest_title=question.question_text,
209+
dest_width=600,
210+
dest_height=400
211+
)
212+
213+
return render(
214+
request,
215+
'survey_result.html',
216+
dict(svg=svg.read())
217+
)

templates/survey_result.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
{{svg|safe}}
4+
</body>
5+
</html>

0 commit comments

Comments
 (0)