1# Copyright(c) 2009-2010 by Yaco S.L. <lgs@yaco.es> 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 18import sys 19 20import cairo 21 22import pycha.stackedbar 23 24 25def stackedBarChart(output, chartFactory): 26 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 800, 400) 27 28 dataSet = ( 29 ('internal', [(0, 8), (1, 10), (2, 5), (3, 6)]), 30 ('external', [(0, 5), (1, 2), (2, 4), (3, 8)]), 31 ) 32 33 options = { 34 'background': { 35 'chartColor': '#ffeeff', 36 'baseColor': '#ffffff', 37 'lineColor': '#444444', 38 }, 39 'colorScheme': { 40 'name': 'gradient', 41 'args': { 42 'initialColor': 'red', 43 }, 44 }, 45 'legend': { 46 'hide': True, 47 }, 48 'title': 'Sample Chart' 49 } 50 chart = chartFactory(surface, options) 51 52 chart.addDataset(dataSet) 53 chart.render() 54 55 surface.write_to_png(output) 56 57if __name__ == '__main__': 58 if len(sys.argv) > 1: 59 output = sys.argv[1] 60 else: 61 output = 'stackedbarchart.png' 62 stackedBarChart('v' + output, pycha.stackedbar.StackedVerticalBarChart) 63 stackedBarChart('h' + output, pycha.stackedbar.StackedHorizontalBarChart) 64