Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
2
<HTML>
3
<HEAD>
4
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1">
5
<LINK REL="Start" HREF="index.html">
6
<LINK REL="Contents" HREF="toc.html">
7
<LINK REL="Prev" HREF="814AddingasecondYscale.html">
8
<LINK REL="Next" HREF="816Handlingnullvaluesinlineplots.html">
9
<STYLE TYPE="text/css"><!--
10
BODY { font-family: serif }
11
H1 { font-family: sans-serif }
12
H2 { font-family: sans-serif }
13
H3 { font-family: sans-serif }
14
H4 { font-family: sans-serif }
15
H5 { font-family: sans-serif }
16
H6 { font-family: sans-serif }
17
SUB { font-size: smaller }
18
SUP { font-size: smaller }
19
PRE { font-family: monospace }
20
A { text-decoration: none }
21
--></STYLE>
22
</HEAD>
23
<BODY>
24
<A HREF="toc.html">Contents</A>
25
<A HREF="814AddingasecondYscale.html">Previous</A>
26
<A HREF="816Handlingnullvaluesinlineplots.html">Next</A>
27
<HR NOSHADE>
28
<H3><A NAME="8_1_5">8.1.5 Adding a legend to the graph</A></H3>
29
<P> With more than one plot on the same graph it is necessary to somehow
30
 indicate which plot is which. This is normally done by adding a legend
31
 to the graph.</P>
32
<P> You will see that each plot type has a 'SetLegend()' method which is
33
 used to name that plot in the legend. SO to name the two plots in the
34
 example we have been working with so far we need to add the lines<DIV class="phpscript">
35
<CODE><FONT color="#000000"> <FONT color="#0000BB">&nbsp;$lineplot</FONT><FONT
36
color="#007700">-&gt;</FONT><FONT color="#0000BB">SetLegend</FONT><FONT color="#007700">
37
(</FONT><FONT color="#DD0000">&quot;Plot&nbsp;1&quot;</FONT><FONT color="#007700">);
38
<BR></FONT><FONT color="#0000BB">$lineplot2</FONT><FONT color="#007700">
39
-&gt;</FONT><FONT color="#0000BB">SetLegend</FONT><FONT color="#007700">(</FONT><FONT
40
color="#DD0000">&quot;Plot&nbsp;2&quot;</FONT><FONT color="#007700">);</FONT><FONT color="#0000BB">
41
</FONT></FONT></CODE></DIV></P>
42
<P> to the previous code. The resulting graph is shown below
43
<!--?
44
Example('example5.1','Adding a legend to the graph');
45
?-->
46
 As you can see the legend gets automatically sized depending on how
47
 many plots there are that have legend texts to display. By default it
48
 is placed with it's top right corner close to the upper right edge of
49
 the image. Depending on the image you might want to adjust this or you
50
 might want to add a larger margin which is big enough to accompany the
51
 legend. Let's do both.</P>
52
<P> First we increase the right margin and then we place the legend so
53
 that it is roughly centered. We will also enlarge the overall image so
54
 the plot area doesn't get too squeezed.</P>
55
<P> To modify the legend you access the 'legend' property of the graph.
56
 For a full reference on all the possibilities (changing colors, layout,
57
 etc) see <A href="../ref/Legend.html#_C_LEGEND/">class legend</A> in
58
 the class reference</P>
59
<P> For this we use the legends 'SetPos()' method as in<DIV class="phpscript">
60
<CODE><FONT color="#000000"> <FONT color="#0000BB">&nbsp;$graph</FONT><FONT color="#007700">
61
-&gt;</FONT><FONT color="#0000BB">legend</FONT><FONT color="#007700">-&gt;</FONT><FONT
62
color="#0000BB">Pos</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">
63
0.05</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">0.5</FONT><FONT
64
color="#007700">,</FONT><FONT color="#DD0000">&quot;right&quot;</FONT><FONT color="#007700">
65
,</FONT><FONT color="#DD0000">&quot;center&quot;</FONT><FONT color="#007700">);</FONT><FONT
66
color="#0000BB"></FONT></FONT></CODE></DIV></P>
67
<P></P>
68
<P> Doing this small modification will give the result shown below<DIV class="example">
69
<BR> <A href="exframes/frame_example6.html" target="blank"><IMG border="0"
70
HEIGHT="200"  src="img/example6.png" WIDTH="400"></A>
71
<BR><B>Figure 11:</B> Adjusting the layout to give more rooms for the
72
 legend <A href="exframes/frame_example6.html" target="blank">[src]</A>&nbsp;
73
<P></P>
74
</DIV></P>
75
<P> The above method 'SetPos()' deserves some explanation since it might
76
 not be obvious. You specify the position as a fraction of the overall
77
 width and height of the entire image. This makes it possible for you to
78
 resize the image within disturbing the relative position of the legend.
79
 We will later see that the same method is just to place arbitrary text
80
 in the image.</P>
81
<P> To give added flexibility one must also specify to what edge of the
82
 legend the position given should be relative to. In the example above
83
 we have specified &quot;right&quot; edge on the legend for the for the horizontal
84
 positioning and &quot;center&quot; for the vertical position.</P>
85
<P> This means that the right edge of the legend should be position 5 %
86
 of the image width from the right. If you had specified &quot;left&quot; the the
87
 legends left edge would be positioned 5 % of the image width from the
88
 image left side.</P>
89
<P> By default the legends in the legend box gets stacked on top of each
90
 other. The other possibility is to have them sideways. To adjust this
91
 you use the <A href="../ref/Legend.html#_LEGEND_SETLAYOUT">SetLayout()</A>
92
 method. Using a horizontal layout with the previous example give the
93
 following result.<DIV class="example">
94
<BR> <A href="exframes/frame_example6.1.html" target="blank"><IMG border="0"
95
HEIGHT="240"  src="img/example6.1.png" WIDTH="300"></A>
96
<BR><B>Figure 12:</B> Using a horizontal layout for the legends <A href="exframes/frame_example6.1.html"
97
target="blank">[src]</A>&nbsp;
98
<P></P>
99
</DIV></P>
100
<P></P>
101
<H4>8.1.5.1 Adjusting the layout of the legend</H4>
102
<P> For more advanced fomatting of the legend it is possible to adjust</P>
103
<UL>
104
<LI> The number of columns in the legend</LI>
105
<LI> Specify vertical / horizontal margins for legend columns</LI>
106
</UL>
107
<P> In order to adjust the number of columns used in the legend the
108
 method<I> Legend::SetColumns</I> is used. So for example to have the
109
 legend lined up using three columns the follwing lines have to be added
110
 to teh script<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB">
111
&nbsp;$graph</FONT><FONT color="#007700">-&gt;</FONT><FONT color="#0000BB">
112
legend</FONT><FONT color="#007700">-&gt;</FONT><FONT color="#0000BB">
113
SetColumns</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">3</FONT><FONT
114
color="#007700">);</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV>
115
</P>
116
<P></P>
117
<HR NOSHADE>
118
<A HREF="toc.html">Contents</A>
119
<A HREF="814AddingasecondYscale.html">Previous</A>
120
<A HREF="816Handlingnullvaluesinlineplots.html">Next</A>
121
</BODY>
122
</HTML>