Data labels are descriptive texts assigned to a specific data point. Each series derived from Series has an associated instance of an DataLabels object controlling the displayed texts. It is accessible with the help of the DataLabels property of the Series class.
VB.NET | |
---|---|
Dim datalabels As DataLabels = series.DataLabels |
C# | |
---|---|
DataLabels datalabels = series.DataLabels; |
Controlling the Label Mode of a Series
The mode in which data labels are assigned to data points is controlled by the Mode property. It is of type DataLabelsMode and can accept the following values (for details, see DataLabelsMode Enumeration):
None
Every
Subset
By default it is set to Every. A description of these modes follows.
1. None: The series will not display data labels for its data points.
VB.NET | |
---|---|
bar.DataLabels.Mode = DataLabelsMode.None |
C# | |
---|---|
bar.DataLabels.Mode = DataLabelsMode.None; |
2. Every: When operating in this mode, the series will display a data label for every Nth data points. The N value is specified by the DrawEvery property. By default it is set to 1, which means that by default the series will display a data label for every data point. The following code displays data labels for each odd data point:
VB.NET | |
---|---|
|
C# | |
---|---|
|
In practice you will have to specify a value greater than 1 if you want to increase the readability of a chart with a large number of data points.
3. Subset: When operating in this mode, the series will display a data label for data points whose index is contained in a user-specified set of data point indexes. The following example code will display a data label for the data points from 1 to 5 and data point 7.
VB.NET | |
---|---|
|
C# | |
---|---|
|
This mode can be very useful if you intend to display the data labels on special data points only, for example, on the biggest bar.
Controlling the Format of a Label for a Series
The user can control what information is displayed in each individual data label with the help of a simple formatting string. It is specified in the Format property. The following example displays the bar value and label in the data labels.
VB.NET | |
---|---|
bar.DataLabels.Format = "<value> <label>" |
C# | |
---|---|
bar.DataLabels.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.
Controlling the Appearance of the Data Label Text
The data label text is displayed with the Text property.
Related Examples
Windows Forms: Series Attributes\Data Labels