1# Copyright(c) 2007-2010 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com> 2# 2009 by Yaco S.L. <lgs@yaco.es> 3# 4# This file is part of PyCha. 5# 6# PyCha is free software: you can redistribute it and/or modify 7# it under the terms of the GNU Lesser General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10# 11# PyCha is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU Lesser General Public License for more details. 15# 16# You should have received a copy of the GNU Lesser General Public License 17# along with PyCha. If not, see <http://www.gnu.org/licenses/>. 18 19import cairo 20 21import pycha.pie 22 23 24def pieChart(colorScheme): 25 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 400) 26 27 options = { 28 'background': { 29 'hide': True, 30 }, 31 'colorScheme': colorScheme, 32 'title': colorScheme['name'], 33 } 34 chart = pycha.pie.PieChart(surface, options) 35 36 dataSet = ( 37 ('dataset 1', ((0, 10), )), 38 ('dataset 2', ((0, 15), )), 39 ('dataset 3', ((0, 20), )), 40 ('dataset 4', ((0, 25), )), 41 ('dataset 5', ((0, 30), )), 42 ('dataset 6', ((0, 20), )), 43 ('dataset 7', ((0, 40), )), 44 ) 45 46 chart.addDataset(dataSet) 47 chart.render() 48 49 output = colorScheme['name'] + '.png' 50 surface.write_to_png(output) 51 52if __name__ == '__main__': 53 pieChart({'name': 'gradient', 'args': {'initialColor': 'red'}}) 54 55 colors = ('#ff0000', '#00ff00', '#0000ff', 56 '#00ffff', '#000000', '#ff00ff', 57 '#ffff00') 58 pieChart({'name': 'fixed', 'args': {'colors': colors}}) 59 60 pieChart({'name': 'rainbow', 'args': {'initialColor': 'red'}}) 61