ChartDataLabel Class

Represents data label on a chart point or trendline.
Inheritance Hierarchy

Namespace:  Aspose.Words.Drawing.Charts
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.4
public class ChartDataLabel

The ChartDataLabel type exposes the following members.

Public propertyCode exampleIndex
Specifies the index of the containing element. This index shall determine which of the parent's children collection this element applies to. Default value is 0.
Public propertyIsHidden
Gets/sets a flag indicating whether this label is hidden. The default value is false.
Public propertyCode exampleIsVisible
Returns true if this data label has something to display.
Public propertyCode exampleNumberFormat
Returns number format of the parent element.
Public propertyCode exampleSeparator
Gets or sets string separator used for the data labels on a chart. The default is a comma, except for pie charts showing only category name and percentage, when a line break shall be used instead.
Public propertyCode exampleShowBubbleSize
Allows to specify if bubble size is to be displayed for the data labels on a chart. Applies only to Bubble charts. Default value is false.
Public propertyCode exampleShowCategoryName
Allows to specify if category name is to be displayed for the data labels on a chart. Default value is false.
Public propertyCode exampleShowDataLabelsRange
Allows to specify if values from data labels range to be displayed in the data labels. Default value is false.
Public propertyCode exampleShowLeaderLines
Allows to specify if data label leader lines need be shown. Default value is false.
Public propertyCode exampleShowLegendKey
Allows to specify if legend key is to be displayed for the data labels on a chart. Default value is false.
Public propertyCode exampleShowPercentage
Allows to specify if percentage value is to be displayed for the data labels on a chart. Default value is false.
Public propertyCode exampleShowSeriesName
Returns or sets a Boolean to indicate the series name display behavior for the data labels on a chart. True to show the series name. False to hide. By default false.
Public propertyCode exampleShowValue
Allows to specify if values are to be displayed in the data labels. Default value is false.
Public methodClearFormat
Clears format of this data label. The properties are set to the default values defined in the parent data label collection.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)
On a series, the ChartDataLabel object is a member of the ChartDataLabelCollection. The ChartDataLabelCollection contains a ChartDataLabel object for each point.
Shows how to apply labels to data points in a chart.
public void ChartDataLabels()
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Use a document builder to insert a bar chart
    Shape chartShape = builder.InsertChart(ChartType.Line, 400, 300);

    // Get the chart object from the containing shape
    Chart chart = chartShape.Chart;

    // The chart already contains demo data comprised of 3 series each with 4 categories
    Assert.AreEqual(3, chart.Series.Count);
    Assert.AreEqual("Series 1", chart.Series[0].Name);

    // Apply data labels to every series in the graph
    foreach (ChartSeries series in chart.Series)
        ApplyDataLabels(series, 4, "000.0", ", ");
        Assert.AreEqual(4, series.DataLabels.Count);

    // Get the enumerator for a data label collection
    using (IEnumerator<ChartDataLabel> enumerator = chart.Series[0].DataLabels.GetEnumerator())
        // And use it to go over all the data labels in one series and change their separator
        while (enumerator.MoveNext())
            Assert.AreEqual(", ", enumerator.Current.Separator);
            enumerator.Current.Separator = " & ";

    // If the chart looks too busy, we can remove data labels one by one

    // We can also clear an entire data label collection for one whole series

    doc.Save(ArtifactsDir + "Charts.ChartDataLabels.docx");

/// <summary>
/// Apply uniform data labels with custom number format and separator to a number (determined by labelsCount) of data points in a series
/// </summary>
private static void ApplyDataLabels(ChartSeries series, int labelsCount, string numberFormat, string separator)
    for (int i = 0; i < labelsCount; i++)
        series.HasDataLabels = true;

        // Edit the appearance of the new data label
        series.DataLabels[i].ShowCategoryName = true;
        series.DataLabels[i].ShowSeriesName = true;
        series.DataLabels[i].ShowValue = true;
        series.DataLabels[i].ShowLeaderLines = true;
        series.DataLabels[i].ShowLegendKey = true;
        series.DataLabels[i].ShowPercentage = false;

        // Apply number format and separator
        series.DataLabels[i].NumberFormat.FormatCode = numberFormat;
        series.DataLabels[i].Separator = separator;

        // The label automatically becomes visible
See Also