ChartDataLabelCollection class

ChartDataLabelCollection class

Represents a collection of ChartDataLabel. To learn more, visit the Working with Charts documentation article.

Properties

NameDescription
countReturns the number of ChartDataLabel in this collection.
fontProvides access to the font formatting of the data labels of the entire series.
formatProvides access to fill and line formatting of the data labels.
numberFormatGets an ChartNumberFormat instance allowing to set number format for the data labels of the entire series.
orientationGets or sets the text orientation of the data labels of the entire series.
positionGets or sets the position of the data labels.
rotationGets or sets the rotation of the data labels of the entire series in degrees.
separatorGets or sets string separator used for the data labels of the entire series. 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 whether bubble size is to be displayed for the data labels of the entire series. Applies only to Bubble charts. Default value is false.
showCategoryNameAllows to specify whether category name is to be displayed for the data labels of the entire series. Default value is false.
showDataLabelsRangeAllows to specify whether values from data labels range to be displayed in the data labels of the entire series. Default value is false.
showLeaderLinesAllows to specify whether data label leader lines need be shown for the data labels of the entire series. Default value is false.
showLegendKeyAllows to specify whether legend key is to be displayed for the data labels of the entire series. Default value is false.
showPercentageAllows to specify whether percentage value is to be displayed for the data labels of the entire series. Default value is false. Applies only to Pie charts.
showSeriesNameReturns or sets a Boolean to indicate the series name display behavior for the data labels of the entire series. true to show the series name; false to hide. By default false.
showValueAllows to specify whether values are to be displayed in the data labels of the entire series. Default value is false.
this[]

Methods

NameDescription
clearFormat()Clears format of all ChartDataLabel in this 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