com.aspose.words

Class ChartDataLabelCollection

  • java.lang.Object
    • com.aspose.words.ChartDataLabelCollection
  • All Implemented Interfaces:
    java.lang.Iterable
    public class ChartDataLabelCollection 
    extends java.lang.Object

Represents a collection of ChartDataLabel.

Example:

Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
    Chart chart = chartShape.getChart();

    Assert.assertEquals(3, chart.getSeries().getCount());
    Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
    Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
    Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());

    // 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 (ChartSeries series : chart.getSeries())
    {
        applyDataLabels(series, 4, "000.0", ", ");
        Assert.assertEquals(series.getDataLabels().getCount(), 4);
    }

    // Change the separator string for every data label in a series.
    Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
    while (enumerator.hasNext()) {
        Assert.assertEquals(enumerator.next().getSeparator(), ", ");
        enumerator.next().setSeparator(" & ");
    }

    // For a cleaner looking graph, we can remove data labels individually.
    chart.getSeries().get(1).getDataLabels().get(2).clearFormat();

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

    doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}

/// <summary>
/// Apply data labels with custom number format and separator to a number 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);

        Assert.assertFalse(series.getDataLabels().get(i).isVisible());

        series.getDataLabels().get(i).setShowCategoryName(true);
        series.getDataLabels().get(i).setShowSeriesName(true);
        series.getDataLabels().get(i).setShowValue(true);
        series.getDataLabels().get(i).setShowLeaderLines(true);
        series.getDataLabels().get(i).setShowLegendKey(true);
        series.getDataLabels().get(i).setShowPercentage(false);
        series.getDataLabels().get(i).isHidden(false);
        Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());

        series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
        series.getDataLabels().get(i).setSeparator(separator);

        Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        Assert.assertTrue(series.getDataLabels().get(i).isVisible());
        Assert.assertFalse(series.getDataLabels().get(i).isHidden());
    }
}

Property Getters/Setters Summary
intgetCount()
Returns the number of ChartDataLabel in this collection.
ChartNumberFormatgetNumberFormat()
Gets an ChartNumberFormat instance allowing to set number format for the data labels of the entire series.
java.lang.StringgetSeparator()
void
setSeparator(java.lang.Stringvalue)
           Gets 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.
booleangetShowBubbleSize()
void
setShowBubbleSize(booleanvalue)
           Allows 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.
booleangetShowCategoryName()
void
setShowCategoryName(booleanvalue)
           Allows to specify whether category name is to be displayed for the data labels of the entire series. Default value is false.
booleangetShowDataLabelsRange()
void
           Allows to specify whether values from data labels range to be displayed in the data labels of the entire series. Default value is false.
booleangetShowLeaderLines()
void
setShowLeaderLines(booleanvalue)
           Allows to specify whether data label leader lines need be shown for the data labels of the entire series. Default value is false.
booleangetShowLegendKey()
void
setShowLegendKey(booleanvalue)
           Allows to specify whether legend key is to be displayed for the data labels of the entire series. Default value is false.
booleangetShowPercentage()
void
setShowPercentage(booleanvalue)
           Allows 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.
booleangetShowSeriesName()
void
setShowSeriesName(booleanvalue)
           Returns 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.
booleangetShowValue()
void
setShowValue(booleanvalue)
           Allows to specify whether values are to be displayed in the data labels of the entire series. Default value is false.
ChartDataLabelget(int index)
Returns ChartDataLabel for the specified index.
 
Method Summary
ChartDataLabeladd(int index)
Deprecated. Adds new ChartDataLabel at the specified index.
voidclear()
Deprecated. Clears format of all ChartDataLabel in this collection.
voidclearFormat()
Clears format of all ChartDataLabel in this collection.
java.util.Iterator<ChartDataLabel>iterator()
Returns an enumerator object.
voidremoveAt(int index)
Deprecated. Clears format of a ChartDataLabel at the specified index.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Returns the number of ChartDataLabel in this collection.

        Example:

        Shows how to apply labels to data points in a line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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 (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number 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);
        
                Assert.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }
      • getNumberFormat

        public ChartNumberFormat getNumberFormat()
        
        Gets an ChartNumberFormat instance allowing to set number format for the data labels of the entire series.

        Example:

        Shows how to enable and configure data labels for a chart series.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a line chart, then clear its demo data series to start with a clean chart,
        // and then set a title.
        Shape shape = builder.insertChart(ChartType.LINE, 500.0, 300.0);
        Chart chart = shape.getChart();
        chart.getSeries().clear();
        chart.getTitle().setText("Monthly sales report");
        
        // Insert a custom chart series with months as categories for the X-axis,
        // and respective decimal amounts for the Y-axis.
        ChartSeries series = chart.getSeries().add("Revenue", 
            new String[] { "January", "February", "March" }, 
            new double[] { 25.611d, 21.439d, 33.750d });
        
        // Enable data labels, and then apply a custom number format for values displayed in the data labels.
        // This format will treat displayed decimal values as millions of US Dollars.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowValue(true);
        dataLabels.getNumberFormat().setFormatCode("\"US$\" #,##0.000\"M\"");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelNumberFormat.docx");
      • getSeparator/setSeparator

        public java.lang.String getSeparator() / public void setSeparator(java.lang.String value)
        
        Gets 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. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.Separator property.

        Example:

        Shows how to work with data labels of a bubble chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.BUBBLE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Add a custom series with X/Y coordinates and diameter of each of the bubbles. 
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new double[] { 2.9, 3.5, 1.1, 4.0, 4.0 },
            new double[] { 1.9, 8.5, 2.1, 6.0, 1.5 },
            new double[] { 9.0, 4.5, 2.5, 8.0, 5.0 });
        
        // Enable data labels, and then modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowBubbleSize(true);
        dataLabels.setShowCategoryName(true);
        dataLabels.setShowSeriesName(true);
        dataLabels.setSeparator(" & ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsBubbleChart.docx");

        Example:

        Shows how to work with data labels of a pie chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.PIE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Insert a custom chart series with a category name for each of the sectors, and their frequency table.
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new String[] { "Word", "PDF", "Excel" },
            new double[] { 2.7, 3.2, 0.8 });
        
        // Enable data labels that will display both percentage and frequency of each sector, and modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowLeaderLines(true);
        dataLabels.setShowLegendKey(true);
        dataLabels.setShowPercentage(true);
        dataLabels.setShowValue(true);
        dataLabels.setSeparator("; ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsPieChart.docx");
      • getShowBubbleSize/setShowBubbleSize

        public boolean getShowBubbleSize() / public void setShowBubbleSize(boolean value)
        
        Allows 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. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowBubbleSize property.

        Example:

        Shows how to work with data labels of a bubble chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.BUBBLE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Add a custom series with X/Y coordinates and diameter of each of the bubbles. 
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new double[] { 2.9, 3.5, 1.1, 4.0, 4.0 },
            new double[] { 1.9, 8.5, 2.1, 6.0, 1.5 },
            new double[] { 9.0, 4.5, 2.5, 8.0, 5.0 });
        
        // Enable data labels, and then modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowBubbleSize(true);
        dataLabels.setShowCategoryName(true);
        dataLabels.setShowSeriesName(true);
        dataLabels.setSeparator(" & ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsBubbleChart.docx");
      • getShowCategoryName/setShowCategoryName

        public boolean getShowCategoryName() / public void setShowCategoryName(boolean value)
        
        Allows to specify whether category name is to be displayed for the data labels of the entire series. Default value is false. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowCategoryName property.

        Example:

        Shows how to work with data labels of a bubble chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.BUBBLE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Add a custom series with X/Y coordinates and diameter of each of the bubbles. 
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new double[] { 2.9, 3.5, 1.1, 4.0, 4.0 },
            new double[] { 1.9, 8.5, 2.1, 6.0, 1.5 },
            new double[] { 9.0, 4.5, 2.5, 8.0, 5.0 });
        
        // Enable data labels, and then modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowBubbleSize(true);
        dataLabels.setShowCategoryName(true);
        dataLabels.setShowSeriesName(true);
        dataLabels.setSeparator(" & ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsBubbleChart.docx");
      • getShowDataLabelsRange/setShowDataLabelsRange

        public boolean getShowDataLabelsRange() / public void setShowDataLabelsRange(boolean value)
        
        Allows to specify whether values from data labels range to be displayed in the data labels of the entire series. Default value is false. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowDataLabelsRange property.
      • getShowLeaderLines/setShowLeaderLines

        public boolean getShowLeaderLines() / public void setShowLeaderLines(boolean value)
        
        Allows to specify whether data label leader lines need be shown for the data labels of the entire series. Default value is false.

        Applies to Pie charts only. Leader lines create a visual connection between a data label and its corresponding data point.

        Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowLeaderLines property.

        Example:

        Shows how to work with data labels of a pie chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.PIE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Insert a custom chart series with a category name for each of the sectors, and their frequency table.
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new String[] { "Word", "PDF", "Excel" },
            new double[] { 2.7, 3.2, 0.8 });
        
        // Enable data labels that will display both percentage and frequency of each sector, and modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowLeaderLines(true);
        dataLabels.setShowLegendKey(true);
        dataLabels.setShowPercentage(true);
        dataLabels.setShowValue(true);
        dataLabels.setSeparator("; ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsPieChart.docx");
      • getShowLegendKey/setShowLegendKey

        public boolean getShowLegendKey() / public void setShowLegendKey(boolean value)
        
        Allows to specify whether legend key is to be displayed for the data labels of the entire series. Default value is false. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowLegendKey property.

        Example:

        Shows how to work with data labels of a pie chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.PIE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Insert a custom chart series with a category name for each of the sectors, and their frequency table.
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new String[] { "Word", "PDF", "Excel" },
            new double[] { 2.7, 3.2, 0.8 });
        
        // Enable data labels that will display both percentage and frequency of each sector, and modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowLeaderLines(true);
        dataLabels.setShowLegendKey(true);
        dataLabels.setShowPercentage(true);
        dataLabels.setShowValue(true);
        dataLabels.setSeparator("; ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsPieChart.docx");
      • getShowPercentage/setShowPercentage

        public boolean getShowPercentage() / public void setShowPercentage(boolean value)
        
        Allows 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. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowPercentage property.

        Example:

        Shows how to work with data labels of a pie chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.PIE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Insert a custom chart series with a category name for each of the sectors, and their frequency table.
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new String[] { "Word", "PDF", "Excel" },
            new double[] { 2.7, 3.2, 0.8 });
        
        // Enable data labels that will display both percentage and frequency of each sector, and modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowLeaderLines(true);
        dataLabels.setShowLegendKey(true);
        dataLabels.setShowPercentage(true);
        dataLabels.setShowValue(true);
        dataLabels.setSeparator("; ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsPieChart.docx");
      • getShowSeriesName/setShowSeriesName

        public boolean getShowSeriesName() / public void setShowSeriesName(boolean value)
        
        Returns 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. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowSeriesName property.

        Example:

        Shows how to work with data labels of a bubble chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.BUBBLE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Add a custom series with X/Y coordinates and diameter of each of the bubbles. 
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new double[] { 2.9, 3.5, 1.1, 4.0, 4.0 },
            new double[] { 1.9, 8.5, 2.1, 6.0, 1.5 },
            new double[] { 9.0, 4.5, 2.5, 8.0, 5.0 });
        
        // Enable data labels, and then modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowBubbleSize(true);
        dataLabels.setShowCategoryName(true);
        dataLabels.setShowSeriesName(true);
        dataLabels.setSeparator(" & ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsBubbleChart.docx");
      • getShowValue/setShowValue

        public boolean getShowValue() / public void setShowValue(boolean value)
        
        Allows to specify whether values are to be displayed in the data labels of the entire series. Default value is false. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowValue property.

        Example:

        Shows how to work with data labels of a pie chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        // Add a bubble chart, and then clear its demo data series to start with a clean chart.
        Chart chart = builder.insertChart(ChartType.PIE, 500.0, 300.0).getChart();
        chart.getSeries().clear();
        
        // Insert a custom chart series with a category name for each of the sectors, and their frequency table.
        ChartSeries series = chart.getSeries().add("Aspose Test Series",
            new String[] { "Word", "PDF", "Excel" },
            new double[] { 2.7, 3.2, 0.8 });
        
        // Enable data labels that will display both percentage and frequency of each sector, and modify their appearance.
        series.hasDataLabels(true);
        ChartDataLabelCollection dataLabels = series.getDataLabels();
        dataLabels.setShowLeaderLines(true);
        dataLabels.setShowLegendKey(true);
        dataLabels.setShowPercentage(true);
        dataLabels.setShowValue(true);
        dataLabels.setSeparator("; ");
        
        doc.save(getArtifactsDir() + "Charts.DataLabelsPieChart.docx");
      • get

        public ChartDataLabel get(int index)
        
        Returns ChartDataLabel for the specified index.

        Example:

        Shows how to apply labels to data points in a line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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 (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number 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);
        
                Assert.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }
    • Method Detail

      • add

        @Deprecated
        public ChartDataLabel add(int index)
        Deprecated. Adds new ChartDataLabel at the specified index.
        Parameters:
        index - Target data label index.

        Example:

        Shows how to apply labels to data points in a line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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 (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number 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);
        
                Assert.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }
      • clear

        @Deprecated
        public void clear()
        Deprecated. Clears format of all ChartDataLabel in this collection.

        Example:

        Shows how to apply labels to data points in a line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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 (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number 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);
        
                Assert.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }
      • clearFormat

        public void clearFormat()
        Clears format of all ChartDataLabel in this collection.
      • iterator

        public java.util.Iterator<ChartDataLabel> iterator()
        Returns an enumerator object.

        Example:

        Shows how to apply labels to data points in a line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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 (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number 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);
        
                Assert.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }
      • removeAt

        @Deprecated
        public void removeAt(int index)
        Deprecated. Clears format of a ChartDataLabel at the specified index.
        Parameters:
        index - The zero-based index of the chart data label to clear format.

        Example:

        Shows how to apply labels to data points in a line chart.
        public void dataLabels() throws Exception
        {
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
        
            Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
            Chart chart = chartShape.getChart();
        
            Assert.assertEquals(3, chart.getSeries().getCount());
            Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
            Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
            Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
        
            // 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 (ChartSeries series : chart.getSeries())
            {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Change the separator string for every data label in a series.
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // For a cleaner looking graph, we can remove data labels individually.
            chart.getSeries().get(1).getDataLabels().get(2).clearFormat();
        
            // We can also strip an entire series of its data labels at once.
            chart.getSeries().get(2).getDataLabels().clearFormat();
        
            doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
        }
        
        /// <summary>
        /// Apply data labels with custom number format and separator to a number 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);
        
                Assert.assertFalse(series.getDataLabels().get(i).isVisible());
        
                series.getDataLabels().get(i).setShowCategoryName(true);
                series.getDataLabels().get(i).setShowSeriesName(true);
                series.getDataLabels().get(i).setShowValue(true);
                series.getDataLabels().get(i).setShowLeaderLines(true);
                series.getDataLabels().get(i).setShowLegendKey(true);
                series.getDataLabels().get(i).setShowPercentage(false);
                series.getDataLabels().get(i).isHidden(false);
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
        
                series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
                series.getDataLabels().get(i).setSeparator(separator);
        
                Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
                Assert.assertTrue(series.getDataLabels().get(i).isVisible());
                Assert.assertFalse(series.getDataLabels().get(i).isHidden());
            }
        }