ChartDataLabel class

ChartDataLabel class

Represents data label on a chart point or trendline. To learn more, visit the Working with Charts documentation article.

Remarks

On a series, the ChartDataLabel object is a member of the ChartDataLabelCollection. The ChartDataLabelCollection contains a ChartDataLabel object for each point.

Properties

NameDescription
fontProvides access to the font formatting of this data label.
formatProvides access to fill and line formatting of the data label.
indexSpecifies 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.
isHiddenGets/sets a flag indicating whether this label is hidden. The default value is false.
isVisibleReturns true if this data label has something to display.
leftGets or sets the distance of the data label in points from the left edge of the chart or from the position specified by its ChartDataLabel.position property, depending on the value of the ChartDataLabel.leftMode property.
leftModeGets or sets the interpretation mode of the ChartDataLabel.left property value: whether it sets the location of the data label from the left edge of the chart of from the position specified by its ChartDataLabel.position property.
numberFormatReturns number format of the parent element.
orientationGets or sets the orientation of the label text.
positionGets or sets the position of the data label.
rotationGets or sets the rotation of the label in degrees.
separatorGets 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.
showBubbleSizeAllows 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.
showCategoryNameAllows to specify if category name is to be displayed for the data labels on a chart. Default value is false.
showDataLabelsRangeAllows to specify if values from data labels range to be displayed in the data labels. Default value is false.
showLeaderLinesAllows to specify if data label leader lines need be shown. Default value is false.
showLegendKeyAllows to specify if legend key is to be displayed for the data labels on a chart. Default value is false.
showPercentageAllows to specify if percentage value is to be displayed for the data labels on a chart. Default value is false.
showSeriesNameReturns 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.
showValueAllows to specify if values are to be displayed in the data labels. Default value is false.
topGets or sets the distance of the data label in points from the top edge of the chart or from the position specified by its ChartDataLabel.position property, depending on the value of the ChartDataLabel.topMode property.
topModeGets or sets the interpretation mode of the ChartDataLabel.top property value: whether it sets the location of the data label from the top edge of the chart of from the position specified by its ChartDataLabel.position property.

Methods

NameDescription
clearFormat()Clears format of this data label. The properties are set to the default values defined in the parent data label collection.

Examples

Shows how to apply labels to data points in a line chart.

test('DataLabels', () => {
  let doc = new aw.Document();
  let builder = new aw.DocumentBuilder(doc);

  let chartShape = builder.insertChart(aw.Drawing.Charts.ChartType.Line, 400, 300);
  let chart = chartShape.chart;

  expect(chart.series.count).toEqual(3);
  expect(chart.series.at(0).name).toEqual("Series 1");
  expect(chart.series.at(1).name).toEqual("Series 2");
  expect(chart.series.at(2).name).toEqual("Series 3");

  // Apply data labels to every series in the chart.
  // These labels will appear next to each data point in the graph and display its value.
  for (let series of chart.series)
  {
    applyDataLabels(series, 4, "000.0", ", ");
    expect(series.dataLabels.count).toEqual(4);
  }

  // Change the separator string for every data label in a series.
  for (let label of chart.series.at(0).dataLabels)
  {
      expect(label.separator).toEqual(", ");
      label.separator = " & ";
  }

  let dataLabel = chart.series.at(1).dataLabels.at(2);
  dataLabel.format.fill.color = "#FF0000";

  // For a cleaner looking graph, we can remove data labels individually.
  dataLabel.clearFormat();

  // We can also strip an entire series of its data labels at once.
  chart.series.at(2).dataLabels.clearFormat();

  doc.save(base.artifactsDir + "Charts.dataLabels.docx");
});

See Also