Legends

Legends are used to display labels for multiple graphs in a panel. All graph types come with a property 'Label' (of type ILLabel). The label's expression is displayed next to a small visual sample of the graph. Samples of line graphs display a small piece of the line with its same properties (style,color,width) and a marker in the middle (if visible). All marker types are supported. For surface graphs, a small rectangle will be created. Its inner area display the current colormap. The border is configured the same way as the surface grid lines.

If currently multiple graphs are displayed in a panel, every graph will get an individual legend entry. By now all entries will be displayed below each other.

Properties of legends

Legend objects are represented by ILLegend class. Platform specific derived types exist for distinct graphic devices (currently OpenGL only). The legend is accessed by the Legend member of ILPanel. Only one legend can exist for every panel. The ILPanel.Legend property gives access to the following properties of legends:

PropertyTypeDescription
BackgroundColorColorbackground color
BorderILLinePropertiescontrols the style of legend's border
LocationSystem.Drawing.Pointpositions the legend relative to panels' edges. Default: Point.Empty (see below)
OpacityfloatOpacity for legend background. Values range from 0...1f.
SizeSizeSize of legend. Default: Size.Empty (see below)

Size / location of legend

Both, the Size and Location properties are by default set to Empty. This makes ILPanel to automatically position and size the legend according to panels size and to the sizes for legend entries. By assigning a value to Size and or Location, one overrides that default behavior. However, ILLegend will not size the legend smaller than needed to display all graph labels without truncation.

Controlling the legend labels

Text to be displayed next to a graph's sample is controlled by the Label property of any ILGraph. In general, those labels are configurable in a very flexible way. Graph labels support embedded partial TEX expressions as well as color changes and font control. Read details here.

Legend example

The example creates and configures two line graphs, add labels for them and displays the legend.

LegendExample

Code used to create above plot:

private void Form1_Load(object sender, EventArgs e) {
    // create new ILFigure form
    ILFigure fig = new ILFigure(); 
    // some sample data: 2 sinosoidal vectors as columns of X (flipped)
    ILArray X = ILSpecialData.sincos1D(30,1.5) * -1;
    // create 2 graphs out of X
    ILPlot2DGraph[] graphs = fig.Panel.Graphs.AddPlot2DGraph(X); 
    // back colors 
    fig.BackColor = Color.LightGray;
    fig.ActiveSubfigure.BackColor = Color.LightGray; 
    
    // configure 1st line graph
    graphs[0].Marker.Shape = @"\fontsize{13}\yvalue"; 
    graphs[0].Marker.Size = 14;
    graphs[0].Marker.Color = Color.CornflowerBlue; 
    graphs[0].Label.Text = @"\color{GreenYellow}\bfLine\reset + \color{cornflowerblue}TEX marker"; 
    graphs[0].Line.Color = Color.GreenYellow;
    graphs[0].Line.Width = 2; 
    
    // configure 2nd line graph
    graphs[1].Marker.Shape = MarkerStyle.Cross;  
    graphs[1].Marker.Size = 10; 
    graphs[1].Marker.Color = Color.DarkSalmon;
    graphs[1].Label.Text = @"MarkerStyle\color{DarkSalmon}.Cross"; 
    graphs[1].Line.Visible = false; 

    // uncomment, to also create surface (will make line plots less visible)
    //fig.Panel.Graphs.AddSurfGraph(ILSpecialData.sinc(40,50));
    //fig.Panel.Graphs[2].Label.Text = "Surface"; 
    // configure legend 
    fig.Panel.Legend.Visible = true; 
    fig.Panel.Legend.Opacity = 0.9f; 
    fig.Panel.Legend.Location = new Point(30,40);  
    
    //present the form
    fig.ShowDialog(); 
    this.Close(); 
}

Download example project here.

Here comes just another example of a legend displayed for surface graphs:

surface legend

Valid CSS! Valid XHTML 1.0 Transitional