From Steema Software Reference Wiki
Jump to: navigation, search


Contents page
Previous | Next

Tutorial 5 - Legend design

See the coded example, Legend control, in the Visual Basic 5 & 6 demos folder for a working example of some of the techniques outlined in this Tutorial.

Legend control

Legend parameters are accessible via the Chart Editor, Chart tab, Legend page.

Legend parameters. See Legend class help for more information

Style Tab

Legend Style
Legend default Style "Automatic" will put Series point values in the Legend when there is only one Series in the Chart. When the Chart contains more than one Series, "automatic" will put Series names in the Legend. In the Editor use the Dropdown Combobox to obtain values other than the default. If you change the Legend Style to display values and there are more than one Series in your Chart, TeeChart Pro will display the values of the first Series. You may modify the display using custom options. See [#Customising Customising Legends]

TChart1.Legend.LegendStyle = lsLastValues
'Puts the last value of each Series in the Legend box

Text Style
See the TextStyle property for a list of possible Legend text styles.

Vertical Spacing
Allows you to modify the spacing between Legend entries.

Dividing Lines
The Dividing Lines button gives access to a Border Editor window where you can make the lines between Legend entries Visible and change their Color, Style and Width.

This Visible checkbox enables/disables the display of the entire Legend.

Inverting the Legend reverses the order of the Legend entries.

Check Boxes
Changes the Legend Style to "Series Names" and displays a check box next to each series allowing it to be made invisible or visible.

Font Series Color
Changes the color of the font of the Legend text to the series color.

Position Tab


There are 4 positions available using the Alignment property, Top, Bottom, Left and Right. Right is the default position. The default positioning of the Legend will always be outside the Chart. See the section about [#Customising customising] Legends for more information about positioning Legends.

Resize Chart
The Resize Chart property, when not enabled, will draw the legend within the Chart frame area. Whilst this may be satisfactory for some Legend positioning requirements, better control of Legend positioning in relation to the Chart frame can be achieved by using the Legend Margin property.

Changing the Margin property value will move the Chart frame in relation to the Legend, NOT vice versa. Thus, making a Margin value negative will move the Chart over the Legend (increasing the size of the Chart rectangle area). However, the properties are not intended for repositioning of the Legend over the Chart, better to use the techniques outlined in [#Customising Customising Legends].

Position Offset %
0% is defined as a horizontal Legend touching the right Chart canvas border and a vertical Legend touching the top one. Legends are offset relative to these positions.

This check box will disable the Resize Chart property and will enable you to position the Legend in pixels anywhere on the Chart Canvas.

Symbols Tab

Use the Visible property to show or hide the color rectangles (symbols).

Set Width property to define the width of the Legend symbols.

Width Units
Use the WidthUnits property to define how the width must be interpreted.

Use the Position property to set the position of the color rectangles.

Use Continous property to let the different legend color rectangles flow into each other. When set to True, the color rectangles of the different items are drawn fixed to each other (no vertical spacing). When set to False, the color rectangles are drawn as seperate rectangles.

Use the squared property to make the legend color rectangles square.

Default border and Border...
Use these properties to override the default border of the legend symbols with your own customised one.

Title Tab

Here you can add the text you wish to use for the Legend Title and align the the text within the Title frame. Use the Visible checkbox to Hide/Unhide the Title.

Use the properties to change the color, pattern and transparency of the Title area background

Mixing Bevel and Frame properties and manipulating Width gives almost any combination of 3D effects. By checking Round Frame and selecting the radius size will give various rounded corners to the Title area.

Use the many properties related to the Title Text to personalize the Font and related effects.

Use the Visible property to show or hide the Title area background color gradient. An almost infinite number of gradients can be achieved from combining different gradient styles, colours, directions and sub-gradients.

Use the Shadow properties to create a shadow effect for the Title area.

Similar to the Shadow properties, you can use the Emboss properties to create a embossed effect for the Title area.

You can add an image to the Title area background and then modify it in many ways using the different Filters, Style and position properties.

Format Tab

The color property sets the color for the Legend canvas.

Sets the pattern for the Legend canvas.

Makes the legend canvas transparent leaving just the Legend text and symbols on display.

Sets the level of transparency for the legend canvas.

Border Tab

Use the Bevel property to define the Legend's bevel.

Sets Legend Frame properties: Visible, Style, Color and Width.

Sets the size of the Legend's bevel.

Round Frame
Rounds the corners of the Legend Frame.

Text Tab

This page gives access to properties which change the appearance of the Legend text's font, outline, intercharacter spacing and shadow.

Gradient Tab

Use this page to draw a gradient onto the legend canvas and change it's direction and colours.

Shadow Tab

Sets the colour and size of the Legend's shadow.

Emboss Tab

You can add a personalised Embossing effect to the legend canvas by combining the colour, size, transparency and blur properties.

Picture Tab

Adds an image to the Legend canvas which you can then modify in many ways using the different Filters, Style and position properties.

Customising Legends

Legend events offer the option to completely control and define the Legend appearance and content.

OnGetLegendRect event

The Legend outer rectangle, permits changes to the overall size and position of the Legend box. Use in conjunction with OnGetLegendPos to reposition the Chart Legend and contents.


Private Sub TChart1_OnGetLegendRect(Left As Long, Top As Long, Right As Long, Bottom As Long)
Left = Left - 100
Right = Right - 100
End Sub

OnGetLegendPos event

Modifies the contents of the Legend. The following example could be used with the code above to move Legend contents to the new Legend rectangle.

Private Sub TChart1_OnGetLegendPos(ByVal Index As Long, X As Long, Y As Long, XColor As Long)
X = X - 100
End Sub

OnGetLegendText event

Modifies the text of the Legend contents.

Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
LegendText = LegendText   Str$(Index)
End Sub

When placing the Legend within the Chart rectangle area, bear in mind that the Legend paints before Series and Axes and will appear below either of those at any intersection point.



© 1998-2019 Steema Software SL. All rights reserved.