root/tags/0.5.0/examples/piechart.py
| Revision 136, 1.6 kB (checked in by lgs, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | # Copyright (c) 2007-2008 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com> |
| 2 | # |
| 3 | # This file is part of PyCha. |
| 4 | # |
| 5 | # PyCha is free software: you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU Lesser General Public License as published by |
| 7 | # the Free Software Foundation, either version 3 of the License, or |
| 8 | # (at your option) any later version. |
| 9 | # |
| 10 | # PyCha is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU Lesser General Public License for more details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU Lesser General Public License |
| 16 | # along with PyCha. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | import sys |
| 19 | |
| 20 | import cairo |
| 21 | |
| 22 | import pycha.pie |
| 23 | |
| 24 | from lines import lines |
| 25 | |
| 26 | def pieChart(output): |
| 27 | surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 400) |
| 28 | |
| 29 | dataSet = [(line[0], [[0, line[1]]]) for line in lines] |
| 30 | |
| 31 | options = { |
| 32 | 'axis': { |
| 33 | 'x': { |
| 34 | 'ticks': [dict(v=i, label=d[0]) for i, d in enumerate(lines)], |
| 35 | } |
| 36 | }, |
| 37 | 'background': { |
| 38 | 'hide': True, |
| 39 | }, |
| 40 | 'padding': { |
| 41 | 'left': 70, |
| 42 | 'right': 10, |
| 43 | 'top': 0, |
| 44 | 'bottom': 0, |
| 45 | }, |
| 46 | 'legend': { |
| 47 | 'hide': True, |
| 48 | } |
| 49 | } |
| 50 | chart = pycha.pie.PieChart(surface, options) |
| 51 | |
| 52 | chart.addDataset(dataSet) |
| 53 | chart.render() |
| 54 | |
| 55 | surface.write_to_png(output) |
| 56 | |
| 57 | if __name__ == '__main__': |
| 58 | if len(sys.argv) > 1: |
| 59 | output = sys.argv[1] |
| 60 | else: |
| 61 | output = 'piechart.png' |
| 62 | pieChart(output) |
Note: See TracBrowser
for help on using the browser.
