File: start.html

package info (click to toggle)
pygdchart2 0.beta1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 508 kB
  • ctags: 308
  • sloc: python: 1,268; ansic: 1,029; makefile: 6; sh: 1
file content (188 lines) | stat: -rw-r--r-- 10,058 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188


<html>
	<head>
		<LINK REL=StyleSheet HREF="./style/style.css" TYPE="text/css">
	</head>
		<a href="intro.html">&lt;--previous</a> |
	<a href="./index.html">contents</a> |
	<a href="interface.html">next--&gt;</a> 

	<hr>
	<body>
        <h1>Getting Started</h1>
		
<p> This section gives a quick overview of the features of the PyGDChart
library by working through a simple example. We first show the example program,
and the graph it produces, in full. Then we proceed with a line-by-line
analysis, introducing the basic workings of PyGDChart as we go along.</p>

<h2> The Code </h2>

<center>
    <img src="./images/simple.png">
</center>
<p>  </p>
<code>
<table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="#B82619">
	<tr>
		<td>
			<table cellpadding="5" cellspacing="0" border="0" bgcolor="#FFFFFF" width="100%">
				<tr>
					<td valign="top">

<pre><font color="#C00000">import</font> <font color="#000000">gdchart</font>

<font color="#000000">x</font> <font color="#0000C0">=</font> <font color="#000000">gdchart</font><font color="#0000C0">.</font><font color="#000000">Bar3D</font><font color="#0000C0">(</font><font color="#0000C0">)</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">width</font> <font color="#0000C0">=</font> <font color="#0080C0">250</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">height</font> <font color="#0000C0">=</font> <font color="#0080C0">250</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">xtitle</font> <font color="#0000C0">=</font> <font color="#004080">"Weekday"</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">ytitle</font> <font color="#0000C0">=</font> <font color="#004080">"Percentage"</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">title</font> <font color="#0000C0">=</font> <font color="#004080">"Example Graph"</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">ext_color</font> <font color="#0000C0">=</font> <font color="#0000C0">[</font> <font color="#004080">"white"</font><font color="#0000C0">,</font> <font color="#004080">"yellow"</font><font color="#0000C0">,</font> <font color="#004080">"red"</font><font color="#0000C0">,</font> <font color="#004080">"blue"</font><font color="#0000C0">,</font> <font color="#004080">"green"</font><font color="#0000C0">]</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">setData</font><font color="#0000C0">(</font><font color="#0000C0">[</font><font color="#0080C0">20</font><font color="#0000C0">,</font> <font color="#0080C0">100</font><font color="#0000C0">,</font> <font color="#0080C0">80</font><font color="#0000C0">,</font> <font color="#0080C0">30</font><font color="#0000C0">,</font> <font color="#0080C0">50</font><font color="#0000C0">]</font><font color="#0000C0">)</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">setLabels</font><font color="#0000C0">(</font><font color="#0000C0">[</font><font color="#004080">"Mon"</font><font color="#0000C0">,</font> <font color="#004080">"Tue"</font><font color="#0000C0">,</font> <font color="#004080">"Wed"</font><font color="#0000C0">,</font> <font color="#004080">"Thu"</font><font color="#0000C0">,</font> <font color="#004080">"Fri"</font><font color="#0000C0">]</font><font color="#0000C0">)</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">draw</font><font color="#0000C0">(</font><font color="#004080">"simple.png"</font><font color="#0000C0">)</font><font color="#000000"></font></pre>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</code>

<h2> Explanation </h2>

<h3> Choosing a Chart Class </h3>

<code>
<table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="#B82619">
	<tr>
		<td>
			<table cellpadding="5" cellspacing="0" border="0" bgcolor="#FFFFFF" width="100%">
				<tr>
					<td valign="top">

<pre><font color="#000000">x</font> <font color="#0000C0">=</font> <font color="#000000">gdchart</font><font color="#0000C0">.</font><font color="#000000">Bar3D</font><font color="#0000C0">(</font><font color="#0000C0">)</font><font color="#000000"></font></pre>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</code>

<p> The PyGDChart library is based around a number of chart classes, each of
which represents a different chart style. The first step in using PyGDChart is
usually to instantiate one of these classes. In this case, we will be drawing a
3D bar graph. </p>

<h3> Setting Options </h3>

<code>
<table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="#B82619">
	<tr>
		<td>
			<table cellpadding="5" cellspacing="0" border="0" bgcolor="#FFFFFF" width="100%">
				<tr>
					<td valign="top">

<pre><font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">width</font> <font color="#0000C0">=</font> <font color="#0080C0">250</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">height</font> <font color="#0000C0">=</font> <font color="#0080C0">250</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">xtitle</font> <font color="#0000C0">=</font> <font color="#004080">"Weekday"</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">ytitle</font> <font color="#0000C0">=</font> <font color="#004080">"Percentage"</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">title</font> <font color="#0000C0">=</font> <font color="#004080">"Example Graph"</font>
<font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">ext_color</font> <font color="#0000C0">=</font> <font color="#0000C0">[</font> <font color="#004080">"white"</font><font color="#0000C0">,</font> <font color="#004080">"yellow"</font><font color="#0000C0">,</font> <font color="#004080">"red"</font><font color="#0000C0">,</font> <font color="#004080">"blue"</font><font color="#0000C0">,</font> <font color="#004080">"green"</font><font color="#0000C0">]</font><font color="#000000"></font></pre>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</code>

<p> Although they look like simple object attributes, PyGDChart options are
actually "smart" properties. Whenever you assign to, or retreive the value of,
an option, a certain amount of checking and conversion code is run. This allows
us to ensure that values assigned to options are appropriate - for instance, we
can prevent a user from assigning a string to an option when the underlying C
library expects an integer. </p>

<p> "Smart" options can also make things more convenient by performing some
types of automatic data conversion. Note that the code snippet above uses
descriptive names to specify colours. In the underlying library, however,
colours are stored as integers - colour names are converted to the appropriate
integer values on assignment. PyGDChart's colour handling capabilities are
discussed in greater depth <a href="./colours.html">later</a> in this
manual.</p> 

<h3> Data and Labels </h3>

<code>
<table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="#B82619">
	<tr>
		<td>
			<table cellpadding="5" cellspacing="0" border="0" bgcolor="#FFFFFF" width="100%">
				<tr>
					<td valign="top">

<pre><font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">setData</font><font color="#0000C0">(</font><font color="#0000C0">[</font><font color="#0080C0">20</font><font color="#0000C0">,</font> <font color="#0080C0">100</font><font color="#0000C0">,</font> <font color="#0080C0">80</font><font color="#0000C0">,</font> <font color="#0080C0">30</font><font color="#0000C0">,</font> <font color="#0080C0">50</font><font color="#0000C0">]</font><font color="#0000C0">)</font><font color="#000000"></font></pre>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</code>

<p> Each chart type has a .setData() method, but different chart types may
require different data formats.  Bar graphs, like the one in the example, can
be specified using one or more lists of values. If were drawing a <a
href="graphs/floating.html">floating bar graph</a>, however, the data format
would be more complex, since we would have to specify both the upper and lower
bounds for every bar. The data requirements for the various chart types are
discussed in the appropriate sections elsewhere in this manual.</p>

<code>
<table width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="#B82619">
	<tr>
		<td>
			<table cellpadding="5" cellspacing="0" border="0" bgcolor="#FFFFFF" width="100%">
				<tr>
					<td valign="top">

<pre><font color="#000000">x</font><font color="#0000C0">.</font><font color="#000000">setLabels</font><font color="#0000C0">(</font><font color="#0000C0">[</font><font color="#004080">"Mon"</font><font color="#0000C0">,</font> <font color="#004080">"Tue"</font><font color="#0000C0">,</font> <font color="#004080">"Wed"</font><font color="#0000C0">,</font> <font color="#004080">"Thu"</font><font color="#0000C0">,</font> <font color="#004080">"Fri"</font><font color="#0000C0">]</font><font color="#0000C0">)</font><font color="#000000"></font></pre>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</code>

<p> The .setLabels method is used to specify the labels that appear on the X
axis of a graph. In order to avoid ambiguity, PyGDChart ensures that the number
of labels conforms with the number of data points along the X axis.</p>

	</body>
	<hr>
    <table width="100%">
        <tr>
            <td>
                	<a href="intro.html">&lt;--previous</a> |
	<a href="./index.html">contents</a> |
	<a href="interface.html">next--&gt;</a> 

            </td>
            <td align="right">
                (12/31/03)
            </td>
        </tr>
    </table>
	<center> PyGDChart User's Manual </center>
</html>