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:

Browser usage evolution (in %) 00101020203030404050506060707080802002200320042005200620070241.18397435897435504.11538461538464200416.6346.5044871794872456.3051819974897200525451.825432.11206741975974200631557.1455128205129414.83127129280973200785.876.88397435897436257.0200284.6182.20448717948716260.45615922539200384.7287.525260.1681459566075200474.5392.84551282051285289.54549937242246200566498.1660256410256314.0266272189349200658.6603.4865384615385335.33960910883985200714.2100.05448717948718463.2175004482697200215.4205.375459.7613412228797200315.3310.6955128205128460.049354491662220048.9416.0160256410257478.482203693742220059521.3365384615385478.19419042495963200610.4626.6570512820514474.16200466200472007Browser usage evolution (in %)FirefoxChromeIEOthers

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-2020 Roberto Alsina