root/trunk/README.txt

Revision 180, 5.5 kB (checked in by lgs, 3 years ago)

Add the documentation and release notes link to the README file

Line 
1.. contents::
2
3=====
4PyCha
5=====
6
7Pycha is a very simple Python package for drawing charts using the great
8`Cairo <http://www.cairographics.org/>`_ library. Its goals are:
9
10 * Lightweight
11
12 * Simple to use
13 
14 * Nice looking with default values
15 
16 * Customization
17
18It won't try to draw any possible chart on earth but draw the most common ones
19nicely. There are some other options you may want to look at like
20`pyCairoChart <http://bettercom.de/de/pycairochart>`_.
21
22Pycha is based on `Plotr <http://solutoire.com/plotr/>`_ which is based on
23`PlotKit <http://www.liquidx.net/plotkit/>`_. Both libraries are written in
24JavaScript and are great for client web programming. I needed the same for the
25server side so that's the reason I ported Plotr to Python. Now we can deliver
26charts to people with JavaScript disabled or embed them in PDF reports.
27
28Pycha is distributed under the terms of the `GNU Lesser General Public License
29<http://www.gnu.org/licenses/lgpl.html>`_.
30
31Documentation
32=============
33
34Installation
35------------
36
37Pycha needs PyCairo to works since it uses the Cairo graphics library. If you
38use Linux you will probably already have it installed so you don't have to do
39anything. If you use Windows these are the recommended steps for installing
40PyCairo:
41
42   1. Grab the latest PyCairo Windows installer from
43      http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/ You need to use the
44      one that matches your Python version so take the one ending in -py2.4.exe
45      for Python 2.4 or the one ending in -py2.5.exe for Python 2.5
46   2. Install it in your Python environment (just follow the installation
47      program instructions)
48   3. Put the Cairo dlls inside the pycairo directory inside your site-packages
49      directory or anywhere in your path. You can find the dlls at
50      http://www.gimp.org/%7Etml/gimp/win32/downloads.html Go there and download
51      the following packages:
52
53         1. cairo.zip. You just need the libcairo-2.dll file inside that zip
54         2. libpng.zip. You just need the libpng13.dll file inside that zip
55         3. zlib.zip. You just need the zlib1.dll file inside that zip
56
57Pycha is distributed as a Python Egg so is quite easy to install. You just need
58to type the following command:
59
60easy_install pycha
61
62And Easy Install will go to the Cheeseshop and grab the last pycha for you. If
63will also install it for you at no extra cost :-)
64
65Tutorial
66--------
67
68Using pycha is quite simple. You always follow the same 5 simple steps:
69
70   1. Create a Cairo surface to draw the chart on
71   2. Build a list of data sets from which your chart will be created
72   3. Customize the chart options.
73   4. Create the chart, add the datasets and render it
74   5. Save the results into a file or do whatever you want with the Cairo
75      surface
76
77To create the Cairo surface you just need to say the type of surface and its
78dimensions::
79
80   import cairo
81   width, height = (500, 400)
82   surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
83
84Then you should create your data set querying a database or any other data
85source::
86
87   dataSet = (
88     ('dataSet 1', ((0, 1), (1, 3), (2, 2.5))),
89     ('dataSet 2', ((0, 2), (1, 4), (2, 3))),
90     ('dataSet 3', ((0, 5), (1, 1), (2, 0.5))),     
91   )
92
93As you can see, each data set is a tuple where the first element is the name of
94the data set and the second is another tuple composed by points. Each point is a
95two-elements tuple, the first one is the x value and the second the y value.
96
97Not every chart uses all the information of a data set. For example, the Pie
98chart only uses the first point of each dataset and it only uses the y value of
99the point.
100
101Now you may want to specify some options so the chart can be customize changing
102its defaults values. To see the defaults you can check the
103pycha.chart.Chart.__init__ method in the source code. You can use regular
104dictionaries to define your options. For example, imagine you want to hide the
105legend and use a different color for the background::
106
107   options = {
108       'legend': {'hide': True},
109       'background': {'color': '#f0f0f0'},
110   }
111
112Now we are ready to instantiate the chart, add the data set and render it::
113
114   import pycha.bar
115   chart = pycha.bar.VerticalBarChart(surface, options)
116   chart.addDataset(dataSet)
117   chart.render()
118
119
120Right now you can choose among 4 different kind of charts:
121
122    * Pie Charts (pycha.pie.PieChart)
123    * Vertical Bar Charts (pycha.bar.VerticalBarChart)
124    * Horizontal Bar Charts (pycha.bar.HorizontalBarChart)
125    * Line Charts (pycha.bar.LineChart)
126    * Scatterplot Charts (pycha.scatter.ScatterplotChart)
127
128Finally you can write the surface to a graphic file or anything you want using
129the cairo library::
130
131   surface.write_to_png('output.png')
132
133That's it! You can see more examples in the examples directory of the source
134code.
135
136Documentation
137-------------
138
139Adam Przywecki has done a fantastic work writing documentation for Pycha.
140Check it out at http://pycha.yourwei.com/
141
142
143Development
144-----------
145
146You can get the last bleeding edge version of pycha by getting a checkout of
147the subversion repository::
148
149   svn co http://www.lorenzogil.com/svn/pycha/trunk pycha
150
151Don't forget to check the
152`Release Notes <http://www.lorenzogil.com/projects/pycha/wiki/ReleaseNotes/>`_
153for each version to learn the new features and incompatible changes.
154
155Contact
156-------
157
158There is a mailing list about PyCha at http://groups.google.com/group/pycha
159You can join it to ask questions about its use or simply to talk about its
160development. Your ideas and feedback are greatly appreciated!
Note: See TracBrowser for help on using the browser.