Each series derived from SeriesBase has an associated instance of a SeriesLegend object controlling the information displayed for the series in the chart legend. It is accessible through the Legend property of the SeriesBase class.
VB.NET | |
---|---|
Dim appearance As Appearance = series.Appearance |
C# | |
---|---|
Appearance appearance = series.Appearance; |
Controlling the Legend Mode of the Series
The legend mode of a series is controlled with the Mode property of the SeriesLegend object. It is of type SeriesLegendMode and can accept the following values (for details, see SeriesLegendMode Enumeration):
None
Series
DataPoints
SeriesLogic
For example, the following code will display information about the data points of a bar chart:
VB.NET | |
---|---|
bar.Legend.Mode = SeriesLegendMode.DataPoints |
C# | |
---|---|
bar.Legend.Mode = SeriesLegendMode.DataPoints; |
The following is a description of the series legend modes:
1. None: No information will be added to the legend for this series.
2. Series: Only one legend item will be added. The legend mark will be displayed with the fill effect and line properties defined by the series. The legend item text will be extracted from the series name (specified by the Name property of the SeriesBase class).
3. DataPoints: The series will insert a legend item for each data point displayed by the series. The legend mark will be displayed with the fill effect and line properties of the data point it represents.
4. SeriesLogic: Custom series-specific information will be inserted in the legend, which defines the logic used by the series.
Controlling the Text Format of the Legend
When the series legend is operating in DataPoints mode, it inserts information about the data points of the series. The user can control what information is displayed for each individual data point with simple formatting string. It is specified in the Format property. The following example displays the bar value and label in the legend items.
VB.NET | |
---|---|
bar.Legend.Format = "<value> <label>" |
C# | |
---|---|
bar.Legend.Format = "<value> <label>"; |
For a list of the formatting commands and detailed instructions on how to format the values they represent, please refer to the Series Texts Formatting topic.
Related Examples
Windows Forms: Series Attributes\Legend