Skip to main content

Ralsina.Me — Roberto Alsina's website

New Nikola Feature: SVG Charts via Pygal

I can't sleep, so I just whipped to­geth­er a do­cu­tils di­rec­tive that wraps py­gal for Niko­la, my stat­ic site and blog gen­er­a­tor.

So, how do you use it? LIke this:

.. chart:: Bar
    :title: 'Browser usage evolution (in %)'
    :x_labels: ["2002", "2003", "2004", "2005", "2006", "2007"]

    'Firefox', [None, None, 0, 16.6, 25, 31]
    'Chrome',  [None, None, None, None, None, None]
    'IE',      [85.8, 84.6, 84.7, 74.5, 66, 58.6]
    'Others',  [14.2, 15.4, 15.3, 8.9, 9, 10.4]

Which pro­duces this:

In order to use the Chart directive, you must install the "pygal" Python package.

You can cus­tom­ize the out­put a lot, be­cause Py­gal is very con­fig­urable, and it sup­ports a very wide va­ri­ety of chart­s.

Al­so, the charts are some­what in­ter­ac­tive, which is nice.

It's a pa­thet­i­cal­ly sim­plis­tic piece of code but it seems to work well :-)

claudio canepa / 2013-07-30 12:02:

Nice feature.
I see the charts ok in LateralOpinion but as a raw text in planet.python.org.
It not made at all to planeta.python.org.ar (same as last posts in LateralOpinion)

Roberto Alsina / 2013-07-30 12:32:

That's a bug in planet I guess. Inline SVGs are valid HTML :-(

Ok, time to unhack planet python I guess.

damianavila82 / 2013-07-30 17:48:

Really great feature... I did not know about pygal, interesting project...
The implementation is clear and simple... I will test it more deeply soon.
BTW, nice hack for a free night! ;-)


Contents © 2000-2023 Roberto Alsina