root/tags/0.4.1/examples/test.py

Revision 85, 2.4 kB (checked in by lgs, 4 years ago)

Update copyright note to include the 2008 year

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
18import cairo
19
20import pycha.pie
21import pycha.bar
22import pycha.line
23
24def testPie():
25    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 400, 400)
26
27    chart = pycha.pie.PieChart(surface)
28    dataSet = (
29        ('myFirstDataset', [[0, 3]]),
30        ('mySecondDataset', [[0, 1.4]]),
31        ('myThirdDataset', [[0, 0.46]]),
32        ('myFourthDataset', [[0, 0.3]]),
33        )
34
35    chart.addDataset(dataSet)
36    chart.render()
37
38    surface.write_to_png("testpie.png")
39
40def testBar():
41    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500, 300)
42
43    options = {
44        'legend': {
45            'position': {
46                'left': 330
47                }
48            },
49        }
50
51    chart = pycha.bar.VerticalBarChart(surface, options)
52
53    dataSet = (
54        ('myFirstDataset', [[0, 1], [1, 1], [2, 1.414], [3, 1.73]]),
55        ('mySecondDataset', [[0, 0.3], [1, 2.67], [2, 1.34], [3, 1.73]]),
56        ('myThirdDataset', [[0, 0.46], [1, 1.45], [2, 2.5], [3, 1.2]]),
57        ('myFourthDataset', [[0, 0.86], [1, 0.83], [2, 3], [3, 1.73]]),
58    )
59
60    chart.addDataset(dataSet)
61    chart.render()
62
63    surface.write_to_png("testbar.png")
64
65def testLine():
66    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 600, 500)
67
68    chart = pycha.line.LineChart(surface)
69
70    dataSet = (
71        ('myFirstDataset', [[0, 3], [1, 2], [2, 1.414], [3, 2.3]]),
72        ('mySecondDataset', [[0, 1.4], [1, 2.67], [2, 1.34], [3, 1.2]]),
73        ('myThirdDataset', [[0, 0.46], [1, 1.45], [2, 1.0], [3, 1.6]]),
74        ('myFourthDataset', [[0, 0.3], [1, 0.83], [2, 0.7], [3, 0.2]]),
75    )
76
77    chart.addDataset(dataSet)
78    chart.render()
79
80    surface.write_to_png("testline.png")
81
82
83testPie()
84testBar()
85testLine()
Note: See TracBrowser for help on using the browser.