IMSL C# Programmer’s Guide
2D Drawing Elements >> Labels  Previous Page  Contents  Next Page

Labels

Labels annotate data points or pie slices. As a degenerate case they can be used to place text on a chart without drawing a point. Labels are controlled by the value of the attribute LabelType in a Data node.

Multiline labels are allowed. They are created by newline characters in the string that creates the label.

Attribute LabelType

The attribute LabelType takes on one of the following values.

Data Point Labeling Example

This example shows three data sets, each labeled in a different fashion.

The first data set is blue and the points are labeled by the value of their x- coordinates.

The second data set is pink and the points are labeled by the value of their y-coordinates. The data set is drawn with both markers and lines.

The third data set is red and the points are labeled with the Data node’s Title attribute.

(Download Code)


Annotation

Labels can be used to place text on a chart, without an associated point being drawn. In this example a text message is drawn at (1,7) as its bottom left corner.

Note that it is a two line message. Newlines in the string are reflected in the chart.

The label offset is set to zero, so that the message will be placed exactly at (1,7). This overrides the default offset of 2.0 applied to data labels. The text alignment is set to TEXT_X_LEFT | TEXT_Y_BOTTOM, so (1,7) is the lower left corner of the text’s bounding box (see Attribute Title).

No marker or line is drawn because the DataType attribute has its default value of zero.

(Download Code)
using Imsl.Chart2D;
using System.Drawing;

public class SampleLabelMessage : FrameChart {

    public SampleLabelMessage() {
        Chart chart = this.Chart;
        AxisXY axis = new AxisXY(chart);

        double[] y = {4, 6, 2, 1, 8};
        Data data = new Data(axis, y);
        data.DataType = Data.DATA_TYPE_LINE;
        data.LineColor = Color.Pink;

        double[] xLabel = {1.0};
        double[] yLabel = {7.0};
        Data dataMessage = new Data(axis, xLabel, yLabel);
        dataMessage.TextColor = Color.Blue;
        dataMessage.LabelType = Data.LABEL_TYPE_TITLE;
        dataMessage.SetTitle(“This is a\nsample message.”);
        dataMessage.GetTitle().Alignment = 
            Data.TEXT_X_LEFT | Data.TEXT_Y_BOTTOM;
        dataMessage.GetTitle().Offset = 0.0;
    }

    public static void Main(string[] argv) {
        System.Windows.Forms.Application.Run(new SampleLabelMessage());
    }
}



©  Visual Numerics, Inc.  All rights reserved.  Previous Page  Contents  Next Page