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 chart.
public void chartDataLabels() throws Exception {
    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.0, 300.0);

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

    // The chart already contains demo data comprised of 3 series each with 4 categories
    Assert.assertEquals(chart.getSeries().getCount(), 3);
    Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");

    // Apply data labels to every series in the graph
    for (ChartSeries series : chart.getSeries()) {
        applyDataLabels(series, 4, "000.0", ", ");
        Assert.assertEquals(series.getDataLabels().getCount(), 4);
    }

    // Get the enumerator for a data label collection
    Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();

    // And use it to go over all the data labels in one series and change their separator
    while (enumerator.hasNext()) {
        Assert.assertEquals(enumerator.next().getSeparator(), ", ");
        enumerator.next().setSeparator(" & ");
    }

    // If the chart looks too busy, we can remove data labels one by one
    chart.getSeries().get(1).getDataLabels().removeAt(2);

    // We can also clear an entire data label collection for one whole series
    chart.getSeries().get(2).getDataLabels().clear();

    doc.save(getArtifactsDir() + "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 void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        ChartDataLabel label = series.getDataLabels().add(i);
        Assert.assertFalse(label.isVisible());

        // Edit the appearance of the new data label
        label.setShowCategoryName(true);
        label.setShowSeriesName(true);
        label.setShowValue(true);
        label.setShowLeaderLines(true);
        label.setShowLegendKey(true);
        label.setShowPercentage(false);
        Assert.assertFalse(label.getShowDataLabelsRange());

        // Apply number format and separator
        label.getNumberFormat().setFormatCode(numberFormat);
        label.setSeparator(separator);

        // The label automatically becomes visible
        Assert.assertTrue(label.isVisible());
    }
}

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.
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)
Adds new ChartDataLabel at the specified index.
voidclear()
Removes all ChartDataLabel from this collection.
java.util.Iterator<ChartDataLabel>iterator()
Returns an enumerator object.
voidremoveAt(int index)
Removes 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 chart.
        public void chartDataLabels() throws Exception {
            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.0, 300.0);
        
            // Get the chart object from the containing shape
            Chart chart = chartShape.getChart();
        
            // The chart already contains demo data comprised of 3 series each with 4 categories
            Assert.assertEquals(chart.getSeries().getCount(), 3);
            Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");
        
            // Apply data labels to every series in the graph
            for (ChartSeries series : chart.getSeries()) {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Get the enumerator for a data label collection
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
        
            // And use it to go over all the data labels in one series and change their separator
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // If the chart looks too busy, we can remove data labels one by one
            chart.getSeries().get(1).getDataLabels().removeAt(2);
        
            // We can also clear an entire data label collection for one whole series
            chart.getSeries().get(2).getDataLabels().clear();
        
            doc.save(getArtifactsDir() + "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 void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
            for (int i = 0; i < labelsCount; i++) {
                ChartDataLabel label = series.getDataLabels().add(i);
                Assert.assertFalse(label.isVisible());
        
                // Edit the appearance of the new data label
                label.setShowCategoryName(true);
                label.setShowSeriesName(true);
                label.setShowValue(true);
                label.setShowLeaderLines(true);
                label.setShowLegendKey(true);
                label.setShowPercentage(false);
                Assert.assertFalse(label.getShowDataLabelsRange());
        
                // Apply number format and separator
                label.getNumberFormat().setFormatCode(numberFormat);
                label.setSeparator(separator);
        
                // The label automatically becomes visible
                Assert.assertTrue(label.isVisible());
            }
        }
      • 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.
      • 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.
      • 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.
      • 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.

      • 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.
      • 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. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowPercentage property.
      • 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.
      • 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.
      • get

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

        Example:

        Shows how to apply labels to data points in a chart.
        public void chartDataLabels() throws Exception {
            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.0, 300.0);
        
            // Get the chart object from the containing shape
            Chart chart = chartShape.getChart();
        
            // The chart already contains demo data comprised of 3 series each with 4 categories
            Assert.assertEquals(chart.getSeries().getCount(), 3);
            Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");
        
            // Apply data labels to every series in the graph
            for (ChartSeries series : chart.getSeries()) {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Get the enumerator for a data label collection
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
        
            // And use it to go over all the data labels in one series and change their separator
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // If the chart looks too busy, we can remove data labels one by one
            chart.getSeries().get(1).getDataLabels().removeAt(2);
        
            // We can also clear an entire data label collection for one whole series
            chart.getSeries().get(2).getDataLabels().clear();
        
            doc.save(getArtifactsDir() + "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 void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
            for (int i = 0; i < labelsCount; i++) {
                ChartDataLabel label = series.getDataLabels().add(i);
                Assert.assertFalse(label.isVisible());
        
                // Edit the appearance of the new data label
                label.setShowCategoryName(true);
                label.setShowSeriesName(true);
                label.setShowValue(true);
                label.setShowLeaderLines(true);
                label.setShowLegendKey(true);
                label.setShowPercentage(false);
                Assert.assertFalse(label.getShowDataLabelsRange());
        
                // Apply number format and separator
                label.getNumberFormat().setFormatCode(numberFormat);
                label.setSeparator(separator);
        
                // The label automatically becomes visible
                Assert.assertTrue(label.isVisible());
            }
        }
    • Method Detail

      • add

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

        Example:

        Shows how to apply labels to data points in a chart.
        public void chartDataLabels() throws Exception {
            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.0, 300.0);
        
            // Get the chart object from the containing shape
            Chart chart = chartShape.getChart();
        
            // The chart already contains demo data comprised of 3 series each with 4 categories
            Assert.assertEquals(chart.getSeries().getCount(), 3);
            Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");
        
            // Apply data labels to every series in the graph
            for (ChartSeries series : chart.getSeries()) {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Get the enumerator for a data label collection
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
        
            // And use it to go over all the data labels in one series and change their separator
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // If the chart looks too busy, we can remove data labels one by one
            chart.getSeries().get(1).getDataLabels().removeAt(2);
        
            // We can also clear an entire data label collection for one whole series
            chart.getSeries().get(2).getDataLabels().clear();
        
            doc.save(getArtifactsDir() + "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 void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
            for (int i = 0; i < labelsCount; i++) {
                ChartDataLabel label = series.getDataLabels().add(i);
                Assert.assertFalse(label.isVisible());
        
                // Edit the appearance of the new data label
                label.setShowCategoryName(true);
                label.setShowSeriesName(true);
                label.setShowValue(true);
                label.setShowLeaderLines(true);
                label.setShowLegendKey(true);
                label.setShowPercentage(false);
                Assert.assertFalse(label.getShowDataLabelsRange());
        
                // Apply number format and separator
                label.getNumberFormat().setFormatCode(numberFormat);
                label.setSeparator(separator);
        
                // The label automatically becomes visible
                Assert.assertTrue(label.isVisible());
            }
        }
      • clear

        public void clear()
        Removes all ChartDataLabel from this collection.

        Example:

        Shows how to apply labels to data points in a chart.
        public void chartDataLabels() throws Exception {
            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.0, 300.0);
        
            // Get the chart object from the containing shape
            Chart chart = chartShape.getChart();
        
            // The chart already contains demo data comprised of 3 series each with 4 categories
            Assert.assertEquals(chart.getSeries().getCount(), 3);
            Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");
        
            // Apply data labels to every series in the graph
            for (ChartSeries series : chart.getSeries()) {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Get the enumerator for a data label collection
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
        
            // And use it to go over all the data labels in one series and change their separator
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // If the chart looks too busy, we can remove data labels one by one
            chart.getSeries().get(1).getDataLabels().removeAt(2);
        
            // We can also clear an entire data label collection for one whole series
            chart.getSeries().get(2).getDataLabels().clear();
        
            doc.save(getArtifactsDir() + "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 void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
            for (int i = 0; i < labelsCount; i++) {
                ChartDataLabel label = series.getDataLabels().add(i);
                Assert.assertFalse(label.isVisible());
        
                // Edit the appearance of the new data label
                label.setShowCategoryName(true);
                label.setShowSeriesName(true);
                label.setShowValue(true);
                label.setShowLeaderLines(true);
                label.setShowLegendKey(true);
                label.setShowPercentage(false);
                Assert.assertFalse(label.getShowDataLabelsRange());
        
                // Apply number format and separator
                label.getNumberFormat().setFormatCode(numberFormat);
                label.setSeparator(separator);
        
                // The label automatically becomes visible
                Assert.assertTrue(label.isVisible());
            }
        }
      • iterator

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

        Example:

        Shows how to apply labels to data points in a chart.
        public void chartDataLabels() throws Exception {
            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.0, 300.0);
        
            // Get the chart object from the containing shape
            Chart chart = chartShape.getChart();
        
            // The chart already contains demo data comprised of 3 series each with 4 categories
            Assert.assertEquals(chart.getSeries().getCount(), 3);
            Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");
        
            // Apply data labels to every series in the graph
            for (ChartSeries series : chart.getSeries()) {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Get the enumerator for a data label collection
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
        
            // And use it to go over all the data labels in one series and change their separator
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // If the chart looks too busy, we can remove data labels one by one
            chart.getSeries().get(1).getDataLabels().removeAt(2);
        
            // We can also clear an entire data label collection for one whole series
            chart.getSeries().get(2).getDataLabels().clear();
        
            doc.save(getArtifactsDir() + "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 void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
            for (int i = 0; i < labelsCount; i++) {
                ChartDataLabel label = series.getDataLabels().add(i);
                Assert.assertFalse(label.isVisible());
        
                // Edit the appearance of the new data label
                label.setShowCategoryName(true);
                label.setShowSeriesName(true);
                label.setShowValue(true);
                label.setShowLeaderLines(true);
                label.setShowLegendKey(true);
                label.setShowPercentage(false);
                Assert.assertFalse(label.getShowDataLabelsRange());
        
                // Apply number format and separator
                label.getNumberFormat().setFormatCode(numberFormat);
                label.setSeparator(separator);
        
                // The label automatically becomes visible
                Assert.assertTrue(label.isVisible());
            }
        }
      • removeAt

        public void removeAt(int index)
        Removes a ChartDataLabel at the specified index.
        Parameters:
        index - The zero-based index of the chart data label to remove.

        Example:

        Shows how to apply labels to data points in a chart.
        public void chartDataLabels() throws Exception {
            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.0, 300.0);
        
            // Get the chart object from the containing shape
            Chart chart = chartShape.getChart();
        
            // The chart already contains demo data comprised of 3 series each with 4 categories
            Assert.assertEquals(chart.getSeries().getCount(), 3);
            Assert.assertEquals(chart.getSeries().get(0).getName(), "Series 1");
        
            // Apply data labels to every series in the graph
            for (ChartSeries series : chart.getSeries()) {
                applyDataLabels(series, 4, "000.0", ", ");
                Assert.assertEquals(series.getDataLabels().getCount(), 4);
            }
        
            // Get the enumerator for a data label collection
            Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
        
            // And use it to go over all the data labels in one series and change their separator
            while (enumerator.hasNext()) {
                Assert.assertEquals(enumerator.next().getSeparator(), ", ");
                enumerator.next().setSeparator(" & ");
            }
        
            // If the chart looks too busy, we can remove data labels one by one
            chart.getSeries().get(1).getDataLabels().removeAt(2);
        
            // We can also clear an entire data label collection for one whole series
            chart.getSeries().get(2).getDataLabels().clear();
        
            doc.save(getArtifactsDir() + "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 void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
            for (int i = 0; i < labelsCount; i++) {
                ChartDataLabel label = series.getDataLabels().add(i);
                Assert.assertFalse(label.isVisible());
        
                // Edit the appearance of the new data label
                label.setShowCategoryName(true);
                label.setShowSeriesName(true);
                label.setShowValue(true);
                label.setShowLeaderLines(true);
                label.setShowLegendKey(true);
                label.setShowPercentage(false);
                Assert.assertFalse(label.getShowDataLabelsRange());
        
                // Apply number format and separator
                label.getNumberFormat().setFormatCode(numberFormat);
                label.setSeparator(separator);
        
                // The label automatically becomes visible
                Assert.assertTrue(label.isVisible());
            }
        }