1
# Copyright (c) 2007-2008 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
3
# This file is part of PyCha.
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.
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.
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/>.
26
def barChart(output, chartFactory):
27
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500, 300)
30
('Tainan', [(i, l[1]) for i, l in enumerate(precip.Tainan)]),
31
('Paris', [(i, l[1]) for i, l in enumerate(precip.Paris)]),
37
'ticks': [dict(v=i, label=l[0]) for i, l in enumerate(precip.Tainan)],
44
'label': 'Precipitation (mm)'
48
'chartColor': '#d8e7ec',
49
'baseColor': '#efebe7',
50
'lineColor': '#444444'
52
'colorScheme': '#6eafc1',
55
'position': {'top': 5, 'left': 5},
61
'title': 'Monthly Precipitation'
63
chart = chartFactory(surface, options)
65
chart.addDataset(dataSet)
68
surface.write_to_png(output)
70
if __name__ == '__main__':
74
output = 'barchart.png'
75
barChart('v' + output, pycha.bar.VerticalBarChart)
76
barChart('h' + output, pycha.bar.HorizontalBarChart)