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="714AddingasecondYscale.html">
8
<LINK REL="Next" HREF="716Handlingnullvaluesinlineplots.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="714AddingasecondYscale.html">Previous</A>
26
<A HREF="716Handlingnullvaluesinlineplots.html">Next</A>
27
<HR NOSHADE>
28
<H3><A NAME="7_1_5">7.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<DIV class="example">
43
<BR> <A href="exframes/frame_example5.1.html" target="blank"><IMG border="0"
44
HEIGHT="200"       src="img/img/img/img/img/img/example5.1.png" WIDTH="300"></A>
45
<BR><B>Figure 12:</B> Adding a legend to the graph <A href="exframes/frame_example5.1.html"
46
target="blank">[src]</A>&nbsp;
47
<P></P>
48
</DIV></P>
49
<P> As you can see the legend gets automatically sized depending on how
50
 many plots there are that have legend texts to display. By default it
51
 is placed with it's top right corner close to the upper right edge of
52
 the image. Depending on the image you might want to adjust this or you
53
 might want to add a larger margin which is big enough to accompany the
54
 legend. Let's do both.</P>
55
<P> First we increase the right margin and then we place the legend so
56
 that it is roughly centered. We will also enlarge the overall image so
57
 the plot area doesn't get too squeezed.</P>
58
<P> To modify the legend you access the 'legend' property of the graph.
59
 For a full reference on all the possibilities (changing colors, layout,
60
 etc) see <A href="../ref/Legend.html#_C_LEGEND/">class legend</A> in
61
 the class reference</P>
62
<P> For this we use the legends 'SetPos()' method as in<DIV class="phpscript">
63
<CODE><FONT color="#000000"> <FONT color="#0000BB">&nbsp;$graph</FONT><FONT color="#007700">
64
-&gt;</FONT><FONT color="#0000BB">legend</FONT><FONT color="#007700">-&gt;</FONT><FONT
65
color="#0000BB">Pos</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">
66
0.05</FONT><FONT color="#007700">,</FONT><FONT color="#0000BB">0.5</FONT><FONT
67
color="#007700">,</FONT><FONT color="#DD0000">&quot;right&quot;</FONT><FONT color="#007700">
68
,</FONT><FONT color="#DD0000">&quot;center&quot;</FONT><FONT color="#007700">);</FONT><FONT
69
color="#0000BB"></FONT></FONT></CODE></DIV></P>
70
<P></P>
71
<P> Doing this small modification will give the result shown below<DIV class="example">
72
<BR> <A href="exframes/frame_example6.html" target="blank"><IMG border="0"
73
HEIGHT="200"       src="img/img/img/img/img/img/example6.png" WIDTH="400"></A>
74
<BR><B>Figure 13:</B> Adjusting the layout to give more rooms for the
75
 legend <A href="exframes/frame_example6.html" target="blank">[src]</A>&nbsp;
76
<P></P>
77
</DIV></P>
78
<P> The above method 'SetPos()' deserves some explanation since it might
79
 not be obvious. You specify the position as a fraction of the overall
80
 width and height of the entire image. This makes it possible for you to
81
 resize the image within disturbing the relative position of the legend.
82
 We will later see that the same method is just to place arbitrary text
83
 in the image.</P>
84
<P> To give added flexibility one must also specify to what edge of the
85
 legend the position given should be relative to. In the example above
86
 we have specified &quot;right&quot; edge on the legend for the for the horizontal
87
 positioning and &quot;center&quot; for the vertical position.</P>
88
<P> This means that the right edge of the legend should be position 5 %
89
 of the image width from the right. If you had specified &quot;left&quot; the the
90
 legends left edge would be positioned 5 % of the image width from the
91
 image left side.</P>
92
<P> By default the legends in the legend box gets stacked on top of each
93
 other. The other possibility is to have them sideways. To adjust this
94
 you use the <A href="../ref/Legend.html#_LEGEND_SETLAYOUT">SetLayout()</A>
95
 method. Using a horizontal layout with the previous example give the
96
 following result.<DIV class="example">
97
<BR> <A href="exframes/frame_example6.1.html" target="blank"><IMG border="0"
98
HEIGHT="240"       src="img/img/img/img/img/img/example6.1.png" WIDTH="300"></A>
99
<BR><B>Figure 14:</B> Using a horizontal layout for the legends <A href="exframes/frame_example6.1.html"
100
target="blank">[src]</A>&nbsp;
101
<P></P>
102
</DIV></P>
103
<P></P>
104
<H4>7.1.5.1 Adjusting the layout of the legend</H4>
105
<P> For more advanced fomatting of the legend it is possible to adjust</P>
106
<UL>
107
<LI> The number of columns in the legend</LI>
108
<LI> Specify vertical / horizontal margins for legend columns</LI>
109
</UL>
110
<P> In order to adjust the number of columns used in the legend the
111
 method<I> Legend::SetColumns</I> is used. So for example to have the
112
 legend lined up using three columns the follwing lines have to be added
113
 to teh script<DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB">
114
&nbsp;$graph</FONT><FONT color="#007700">-&gt;</FONT><FONT color="#0000BB">
115
legend</FONT><FONT color="#007700">-&gt;</FONT><FONT color="#0000BB">
116
SetColumns</FONT><FONT color="#007700">(</FONT><FONT color="#0000BB">3</FONT><FONT
117
color="#007700">);</FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV>
118
</P>
119
<P></P>
120
<HR NOSHADE>
121
<A HREF="toc.html">Contents</A>
122
<A HREF="714AddingasecondYscale.html">Previous</A>
123
<A HREF="716Handlingnullvaluesinlineplots.html">Next</A>
124
</BODY>
125
</HTML>