[ class tree: graphpite ] [ index: graphpite ] [ all elements ]
Prev Next

Using Legends

The Image_Graph Tutorial

Using Legends

There are 2 main ways to display legends using Image_Graph.

  • As a box, overlayed on the plotarea

  • As a box, displayed somewhere besides/above/below the plotarea

Overlayed Legends

The 1st way will display a box that is placed (by default in the upper-right corner) of the plotarea. This is the easiest way to add the legend:

1 ...
2 $Legend =& $Plotarea->add(new Image_Graph_Legend());
3 ...

Note that a Image_Graph_Legend is added to a PlotArea.

By displaying the legend in the upper-right corner it could overlap your plot hiding information. However you have the possibility to display the legend in another "corner" of the plot.

1 ...
3 ...

This will make it appear in the bottom-left corner of the plot. Use IMAGE_GRAPH_ALIGN_BOTTOM, IMAGE_GRAPH_ALIGN_TOP, IMAGE_GRAPH_ALIGN_LEFT and IMAGE_GRAPH_ALIGN_RIGHT for corner positions.

Layouted Legends

The 2nd way is (slightly) more complex, but will allow you to,display legends "outside" the plot, thereby not overlapping. This is done in the same using layouts (Plot Layout).

1 ...
2 $Graph->add(
3 new Image_Graph_Layout_Vertical(
4 $Plotarea = new Image_Graph_Plotarea(),
5 $Legend = new Image_Graph_Legend(),
6 95
7 )
8 );
9 $Legend->setPlotArea($Plotarea);
10 ...

Note that you have to link the Image_Graph_Legend to the Image_Graph_Plotarea explicitly. In the 1st option, this is done implicitly, since you add the legend to the plotarea. Using this method you add the legend to a (in this case) Image_Graph_Layout_Vertical which is added to a Image_Graph, leaving the legend with "no idea" of what plot to show legend for. So you need to have the $Legend->setPlotArea($Plotarea); for things to work..

This will also give the possibility to place the legend wherever you want, fx:

1 ...
2 $Graph->add(
3 new Image_Graph_Layout_Vertical(
4 $PlotArea = new Image_Graph_Plotarea(),
5 new Image_Graph_Layout_Horizontal(
6 new Image_Graph_Plotarea(),
7 new Image_Graph_Layout_Vertical(
8 new Image_Graph_Plotarea(),
9 $Legend = new Image_Graph_Legend()
10 )
11 )
12 )
13 );
14 $Legend->setPlotArea($Plotarea);
15 ...

Which will cause the Image_Graph_Legend to be displayed in the lower-right eigth' of the graph, where the linked Image_Graph_Plotarea is displayed in the upper half

Prev Up Next
Plot Layout How to use Image_Graph Graph example

Documentation generated on Wed, 15 Sep 2004 10:30:00 +0200 by phpDocumentor 1.2.3