| Contents > SharpPlot > Methods | Index |
SharpPlot.DrawKey Method
This will draw and clear any pending keys, using the current setting of key text. It is called automatically on Rendering the completed chart, so is only required if you need an exact key locationor a custom-designed key.
Example
sp.KeyStyle = KeyStyles.Boxed|KeyStyles.Vertical|KeyStyles.Shadowed|KeyStyles.Rounded; sp.SetKeyBackground(Color.SlateBlue,FillStyle.Solid); sp.SetKeyFont("Arial,sans",12,FontStyle.Bold,Color.Orange); sp.SetKeyText(new string[]{"First","Second"}); sp.DrawKey(2,260);
Overloads
- public void DrawKey();
- public void DrawKey(double keyPositionX,double keyPositionY);
- public void DrawKey(double keyPositionX,double keyPositionY,KeyDefinition[] keyDefinition);
Description
The chart Key or Legend consists of small placeholders for each line or filled area (appropriately coloured and styled) with an item of descriptive text for each. When any of the Draw methods is called to create a chart (you may call these repeatedly with various series to reuse the same set of axes) a placeholder is stored away to represent all the series plotted on that call. When the chart is rendered, DrawKey is called automatically to check if any KeyText has been set for the various series. If so, a placeholder and associated text are drawn as specified in the KeyStyle setting.
This method may be used to position the key by hand anywhere in the chart area instead of at one of the many default locations which may be given in the style. It should always be called after all the charts have been drawn, otherwise the key placeholders will not be available for all the data series.
It is possible to override the automatic key-generation process completely using the first of the 3 overloads shown, passing an array of key-definitions as the 3rd argument.
sp.SetKeyText(new string[] {"Corals","Latiproductus"});
sp.KeyStyle = KeyStyles.Vertical|KeyStyles.Boxed;
sp.DrawKey(72,25,
new KeyDefinition[] {
new KeyDefinition(2,Color.Maroon),
new KeyDefinition(2,Color.Green) } )
This example is from the Wise Eels Bridge cellular plot in the sample set.

