Version 2.0
Index : Using Legends


Using Legends
 

Legends are the color-coded reference blocks that appear on the side of graphs so the viewer can associate the colors used for the data on the graph with a text description. There are several different ways supplying data and formatting the legend in CFXGraphicsServer, and this tutorial will cover all of them.


Supplying Legend Data

Data can be supplied for legends on either a point-by-point basis, or a set-by-set basis. We use the same attributes for either method, and in this chapter we will look at how to differentiate between the two. The attributes to use for supplying the legend data are as follows:

DB_LegendSet
ST_LegendByPoint
(Sets the database field to use for the individual point legend)
(Sets the static data to use for the individual point legend)

For the purposes of this tutorial, we will just be looking at the ST_LegendByPoint attribute, but the DB_LegendSet works in much the same way. If you are unsure about the differences of using static and dynamic datasources in CFXGraphicsServer please see the tutorial on Static and Dynamic Data Sources.

Firstly, if you are using a single-set graph, CFXGraphicsServer will create a legend on a point-by-point basis. This means that each item in the legend will refer to a single data item on the graph. Therefore, you need to supply legend entries for the same number of points in that dataset; so if your dataset contained 5 points, you would supply 5 legend entries. Let's have a look at an example:

 
A single-set graph with a legend
 
<CFX_GraphicsServer
GraphType="3"
ST_DataSet0="2,1,3,5,6"
LegendBySet="P1,P2,P3,P4,P5"
>

As you can see, each point on the graph now has a legend as specified by ST_LegendByPoint.

Now, if we are to use a multiple-set graph, CFXGraphicsServer will create a legend on a set-by-set basis. This means that each item in the legend will refer to an idividual dataset on the graph. Therefore, you need to supply legend entries for the same number of datasets on the graph; so if your graph contained 3 datasets, you would supply 3 legend entries. Let's have a look at an example:

 
A muliple-set graph with a legend
 
<CFX_GraphicsServer
GraphType="3"
ST_DataSet0="2,1,3,5,6"
ST_DataSet1="6,6,1,7,8"
ST_DataSet2="3,2,4,7,8"
LegendBySet="S1,S2,S3"
>

Supplying Legend Data for Overlay Graphs

In addition to the normal legend entries, you can supply a legend entry for an overlay graph (if one has been used). To do this, we need to use the following attribute:

OverlayLegend
(Sets the text to use for the overlay graph legend entry)

If we add an overlay graph to the previous example (for details of overlay graphs, see the Overlay Graphs tutorial), and add it's legend entry using OverlayLegend, we get a graph like this:

 
A muliple-set graph with a legend
 
<CFX_GraphicsServer
GraphType="3"
ST_DataSet0="2,1,3,5,6"
ST_DataSet1="6,6,1,7,8"
ST_DataSet2="3,2,4,7,8"
OverlayGraph="1"
ST_OverlayDataSet="4,1,9,1,6"
LegendBySet="S1,S2,S3" OverlayLegend="OverLay"
>

As you can see, the overlay legend entry has been added to the bottom of the legend and colored accordingly. It should also be noted at this point that the OverlayLegend attribute can be used with single or mutliple-set graphs and will always have the same effect.


Formatting the legend

We can also apply a range of formatting attributes to the legend on a graph. Below is a list of the different attributes we can use for this purpose:

LegendPos
LegendSize
LegendBackColor
LegendForeColor
LegendBackStyle

LegendFontName
LegendFontSize
LegendFontStyle
(Sets the legend position on the graph)
(Sets the legend size)
(Sets the background color of the legend)
(Sets the foreground color of the legend)
(Sets the background style for the legend)

(Sets the font name for the legend)
(Sets the font size for the legend)
(Sets the font style for the legend)

The first five formatting attributes, can be used to modify the appearence of the legend as a whole. The last three are just relevant to the formatting of the font use for the legend. The best way to illustrate these attributes is to display an example of them in use:

 
A single-set graph illustrating the legend formatting attributes
 
<CFX_GraphicsServer
GraphType="3"
ST_DataSet0="2,1,3,5,6"
LegendBySet="P1,P2,P3,P4,P5" LegendPos="4" LegendSize="50" LegendBackColor="3" LegendForeColor="15" LegendBackStyle="2" LegendFontName="$3" LegendFontSize="-120" LegendFontStyle="1"
>

In the example above, we have put the legend on the left of the graph by setting LegendPos to "4". Setting LegendSize to "50" has halved the space between the legend entries. Setting LegendBackColor has changed the color of the legend box itself, whereas setting LegendForeColor sets the color of the font used on the legend. Finally, setting LegendBackStyle to "2" has added a 'drop shadow' to the legend box.

For more details on formatting font attributes, please see the Fonts tutorial. As always, for details of the input values that all of these attributes can accept, please click the relevant link to be taken to the reference page for that attribute.


[footer]