root/trunk/docs/tutorial.rst

Revision 145, 2.0 kB (checked in by lgs, 3 years ago)

Import docs created by Adam Przywecki

Line 
1.. index:: tutorial
2.. _tutorial:
3
4********
5Tutorial
6********
7
8Using PyCha is quite simple. You always follow the same 5 simple steps:
9
10   1. Create a Cairo surface to draw the chart on.
11   2. Build a list of data sets from which your chart will be created.
12   3. Customize the chart options.
13   4. Create the chart, add the datasets, and render it.
14   5. Save the results into a file or do whatever you want with the Cairo surface.
15
16.. index:: create cairo surface 
17.. _creating-cairo-surface:
18   
19Creating a Cairo Surface
20========================
21
22Detailed information on the Cairo library can be found on their `website
23<http://www.cairographics.org/>`_.
24
25To create the Cairo surface, you need to specify the type of surface and its
26dimensions::
27
28   import cairo
29   width, height = (500, 400)
30   surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
31
32.. index:: build dataset
33.. _building-datasets:
34
35Building Datasets
36=================
37
38PyCha requires a dataset in the form::
39
40    dataSet = (
41         ('dataSet 1', ((0, 1), (1, 3), (2, 2.5))),
42         ('dataSet 2', ((0, 2), (1, 4), (2, 3))),
43         ('dataSet 3', ((0, 5), (1, 1), (2, 0.5))),     
44    )
45   
46Each data set is a tuple, of which the first element is the name of the data set
47and the second is a tuple of two points (x, y).
48
49.. index:: customize options
50.. _customizing-options:
51
52Customizing Options
53===================
54
55Please refer to :ref:`changing-defaults`.
56
57.. index:: render chart
58.. _creating-rendering-chart:
59
60Create and Render Chart
61=======================
62
63Now we are ready to instantiate the chart, add the dataset, and render it::
64
65   import pycha.bar
66   chart = pycha.bar.VerticalBarChart(surface, options)
67   chart.addDataset(dataSet)
68   chart.render()
69   
70Please see :ref:`PyCha chart types <pycha-chart-types>` for supported outputs.
71
72.. _saving-results:
73
74Saving Results
75==============
76
77Finally, you can write the surface to a file using the Cairo library::
78
79   surface.write_to_png('output.png')
80
81That's it! Please see :ref:`save-chart-to-file` and :ref:`embed-chart-in-gtk-app`
82for examples.
83
Note: See TracBrowser for help on using the browser.