com.aspose.words
Class ChartDataLabelCollection

java.lang.Object
    extended by 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()
voidsetSeparator(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.
booleangetShowBubbleSize()
voidsetShowBubbleSize(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.
booleangetShowCategoryName()
voidsetShowCategoryName(boolean value)
           Allows to specify whether category name is to be displayed for the data labels of the entire series. Default value is false.
booleangetShowDataLabelsRange()
voidsetShowDataLabelsRange(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.
booleangetShowLeaderLines()
voidsetShowLeaderLines(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.
booleangetShowLegendKey()
voidsetShowLegendKey(boolean value)
           Allows to specify whether legend key is to be displayed for the data labels of the entire series. Default value is false.
booleangetShowPercentage()
voidsetShowPercentage(boolean value)
           Allows to specify whether percentage value is to be displayed for the data labels of the entire series. Default value is false.
booleangetShowSeriesName()
voidsetShowSeriesName(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.
booleangetShowValue()
voidsetShowValue(boolean value)
           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());
    }
}

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 set number format for the data labels of the entire series.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add chart with default data
Shape shape = builder.insertChart(ChartType.LINE, 432.0, 252.0);
// Delete default generated series
shape.getChart().getSeries().clear();

ChartSeries series =
        shape.getChart().getSeries().add("Aspose Test Series", new String[]{"Word", "PDF", "Excel"}, new double[]{2.5, 1.5, 3.5});

ChartDataLabelCollection dataLabels = series.getDataLabels();
// Display chart values in the data labels, by default it is false
dataLabels.setShowValue(true);
// Set currency format for the data labels of the entire series
dataLabels.getNumberFormat().setFormatCode("\"$\"#,##0.00");

doc.save(getArtifactsDir() + "Charts.DefineNumberFormatForDataLabels.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 set default values for the data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert bubble chart
Shape shapeWithBubbleChart = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
// Clear demo data
shapeWithBubbleChart.getChart().getSeries().clear();

ChartSeries bubbleChartSeries = shapeWithBubbleChart.getChart().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});

// Set default values for the bubble chart data labels
ChartDataLabelCollection bubbleChartDataLabels = bubbleChartSeries.getDataLabels();
bubbleChartDataLabels.setShowBubbleSize(true);
bubbleChartDataLabels.setShowCategoryName(true);
bubbleChartDataLabels.setShowSeriesName(true);
bubbleChartDataLabels.setSeparator(" - ");

builder.insertBreak(BreakType.PAGE_BREAK);

// Insert pie chart
Shape shapeWithPieChart = builder.insertChart(ChartType.PIE, 432.0, 252.0);
// Clear demo data
shapeWithPieChart.getChart().getSeries().clear();

ChartSeries pieChartSeries = shapeWithPieChart.getChart().getSeries().add("Aspose Test Series",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Set default values for the pie chart data labels
ChartDataLabelCollection pieChartDataLabels = pieChartSeries.getDataLabels();
pieChartDataLabels.setShowLeaderLines(true);
pieChartDataLabels.setShowLegendKey(true);
pieChartDataLabels.setShowPercentage(true);
pieChartDataLabels.setShowValue(true);

doc.save(getArtifactsDir() + "Charts.WorkWithChartDataLabelCollection.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 set default values for the data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert bubble chart
Shape shapeWithBubbleChart = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
// Clear demo data
shapeWithBubbleChart.getChart().getSeries().clear();

ChartSeries bubbleChartSeries = shapeWithBubbleChart.getChart().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});

// Set default values for the bubble chart data labels
ChartDataLabelCollection bubbleChartDataLabels = bubbleChartSeries.getDataLabels();
bubbleChartDataLabels.setShowBubbleSize(true);
bubbleChartDataLabels.setShowCategoryName(true);
bubbleChartDataLabels.setShowSeriesName(true);
bubbleChartDataLabels.setSeparator(" - ");

builder.insertBreak(BreakType.PAGE_BREAK);

// Insert pie chart
Shape shapeWithPieChart = builder.insertChart(ChartType.PIE, 432.0, 252.0);
// Clear demo data
shapeWithPieChart.getChart().getSeries().clear();

ChartSeries pieChartSeries = shapeWithPieChart.getChart().getSeries().add("Aspose Test Series",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Set default values for the pie chart data labels
ChartDataLabelCollection pieChartDataLabels = pieChartSeries.getDataLabels();
pieChartDataLabels.setShowLeaderLines(true);
pieChartDataLabels.setShowLegendKey(true);
pieChartDataLabels.setShowPercentage(true);
pieChartDataLabels.setShowValue(true);

doc.save(getArtifactsDir() + "Charts.WorkWithChartDataLabelCollection.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 set default values for the data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert bubble chart
Shape shapeWithBubbleChart = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
// Clear demo data
shapeWithBubbleChart.getChart().getSeries().clear();

ChartSeries bubbleChartSeries = shapeWithBubbleChart.getChart().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});

// Set default values for the bubble chart data labels
ChartDataLabelCollection bubbleChartDataLabels = bubbleChartSeries.getDataLabels();
bubbleChartDataLabels.setShowBubbleSize(true);
bubbleChartDataLabels.setShowCategoryName(true);
bubbleChartDataLabels.setShowSeriesName(true);
bubbleChartDataLabels.setSeparator(" - ");

builder.insertBreak(BreakType.PAGE_BREAK);

// Insert pie chart
Shape shapeWithPieChart = builder.insertChart(ChartType.PIE, 432.0, 252.0);
// Clear demo data
shapeWithPieChart.getChart().getSeries().clear();

ChartSeries pieChartSeries = shapeWithPieChart.getChart().getSeries().add("Aspose Test Series",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Set default values for the pie chart data labels
ChartDataLabelCollection pieChartDataLabels = pieChartSeries.getDataLabels();
pieChartDataLabels.setShowLeaderLines(true);
pieChartDataLabels.setShowLegendKey(true);
pieChartDataLabels.setShowPercentage(true);
pieChartDataLabels.setShowValue(true);

doc.save(getArtifactsDir() + "Charts.WorkWithChartDataLabelCollection.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 set default values for the data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert bubble chart
Shape shapeWithBubbleChart = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
// Clear demo data
shapeWithBubbleChart.getChart().getSeries().clear();

ChartSeries bubbleChartSeries = shapeWithBubbleChart.getChart().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});

// Set default values for the bubble chart data labels
ChartDataLabelCollection bubbleChartDataLabels = bubbleChartSeries.getDataLabels();
bubbleChartDataLabels.setShowBubbleSize(true);
bubbleChartDataLabels.setShowCategoryName(true);
bubbleChartDataLabels.setShowSeriesName(true);
bubbleChartDataLabels.setSeparator(" - ");

builder.insertBreak(BreakType.PAGE_BREAK);

// Insert pie chart
Shape shapeWithPieChart = builder.insertChart(ChartType.PIE, 432.0, 252.0);
// Clear demo data
shapeWithPieChart.getChart().getSeries().clear();

ChartSeries pieChartSeries = shapeWithPieChart.getChart().getSeries().add("Aspose Test Series",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Set default values for the pie chart data labels
ChartDataLabelCollection pieChartDataLabels = pieChartSeries.getDataLabels();
pieChartDataLabels.setShowLeaderLines(true);
pieChartDataLabels.setShowLegendKey(true);
pieChartDataLabels.setShowPercentage(true);
pieChartDataLabels.setShowValue(true);

doc.save(getArtifactsDir() + "Charts.WorkWithChartDataLabelCollection.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 set default values for the data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert bubble chart
Shape shapeWithBubbleChart = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
// Clear demo data
shapeWithBubbleChart.getChart().getSeries().clear();

ChartSeries bubbleChartSeries = shapeWithBubbleChart.getChart().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});

// Set default values for the bubble chart data labels
ChartDataLabelCollection bubbleChartDataLabels = bubbleChartSeries.getDataLabels();
bubbleChartDataLabels.setShowBubbleSize(true);
bubbleChartDataLabels.setShowCategoryName(true);
bubbleChartDataLabels.setShowSeriesName(true);
bubbleChartDataLabels.setSeparator(" - ");

builder.insertBreak(BreakType.PAGE_BREAK);

// Insert pie chart
Shape shapeWithPieChart = builder.insertChart(ChartType.PIE, 432.0, 252.0);
// Clear demo data
shapeWithPieChart.getChart().getSeries().clear();

ChartSeries pieChartSeries = shapeWithPieChart.getChart().getSeries().add("Aspose Test Series",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Set default values for the pie chart data labels
ChartDataLabelCollection pieChartDataLabels = pieChartSeries.getDataLabels();
pieChartDataLabels.setShowLeaderLines(true);
pieChartDataLabels.setShowLegendKey(true);
pieChartDataLabels.setShowPercentage(true);
pieChartDataLabels.setShowValue(true);

doc.save(getArtifactsDir() + "Charts.WorkWithChartDataLabelCollection.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. Value defined for this property can be overridden for an individual data label with using the ChartDataLabel.ShowPercentage property.

Example:

Shows how to set default values for the data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert bubble chart
Shape shapeWithBubbleChart = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
// Clear demo data
shapeWithBubbleChart.getChart().getSeries().clear();

ChartSeries bubbleChartSeries = shapeWithBubbleChart.getChart().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});

// Set default values for the bubble chart data labels
ChartDataLabelCollection bubbleChartDataLabels = bubbleChartSeries.getDataLabels();
bubbleChartDataLabels.setShowBubbleSize(true);
bubbleChartDataLabels.setShowCategoryName(true);
bubbleChartDataLabels.setShowSeriesName(true);
bubbleChartDataLabels.setSeparator(" - ");

builder.insertBreak(BreakType.PAGE_BREAK);

// Insert pie chart
Shape shapeWithPieChart = builder.insertChart(ChartType.PIE, 432.0, 252.0);
// Clear demo data
shapeWithPieChart.getChart().getSeries().clear();

ChartSeries pieChartSeries = shapeWithPieChart.getChart().getSeries().add("Aspose Test Series",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Set default values for the pie chart data labels
ChartDataLabelCollection pieChartDataLabels = pieChartSeries.getDataLabels();
pieChartDataLabels.setShowLeaderLines(true);
pieChartDataLabels.setShowLegendKey(true);
pieChartDataLabels.setShowPercentage(true);
pieChartDataLabels.setShowValue(true);

doc.save(getArtifactsDir() + "Charts.WorkWithChartDataLabelCollection.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 set default values for the data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert bubble chart
Shape shapeWithBubbleChart = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
// Clear demo data
shapeWithBubbleChart.getChart().getSeries().clear();

ChartSeries bubbleChartSeries = shapeWithBubbleChart.getChart().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});

// Set default values for the bubble chart data labels
ChartDataLabelCollection bubbleChartDataLabels = bubbleChartSeries.getDataLabels();
bubbleChartDataLabels.setShowBubbleSize(true);
bubbleChartDataLabels.setShowCategoryName(true);
bubbleChartDataLabels.setShowSeriesName(true);
bubbleChartDataLabels.setSeparator(" - ");

builder.insertBreak(BreakType.PAGE_BREAK);

// Insert pie chart
Shape shapeWithPieChart = builder.insertChart(ChartType.PIE, 432.0, 252.0);
// Clear demo data
shapeWithPieChart.getChart().getSeries().clear();

ChartSeries pieChartSeries = shapeWithPieChart.getChart().getSeries().add("Aspose Test Series",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Set default values for the pie chart data labels
ChartDataLabelCollection pieChartDataLabels = pieChartSeries.getDataLabels();
pieChartDataLabels.setShowLeaderLines(true);
pieChartDataLabels.setShowLegendKey(true);
pieChartDataLabels.setShowPercentage(true);
pieChartDataLabels.setShowValue(true);

doc.save(getArtifactsDir() + "Charts.WorkWithChartDataLabelCollection.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 set default values for the data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert bubble chart
Shape shapeWithBubbleChart = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
// Clear demo data
shapeWithBubbleChart.getChart().getSeries().clear();

ChartSeries bubbleChartSeries = shapeWithBubbleChart.getChart().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});

// Set default values for the bubble chart data labels
ChartDataLabelCollection bubbleChartDataLabels = bubbleChartSeries.getDataLabels();
bubbleChartDataLabels.setShowBubbleSize(true);
bubbleChartDataLabels.setShowCategoryName(true);
bubbleChartDataLabels.setShowSeriesName(true);
bubbleChartDataLabels.setSeparator(" - ");

builder.insertBreak(BreakType.PAGE_BREAK);

// Insert pie chart
Shape shapeWithPieChart = builder.insertChart(ChartType.PIE, 432.0, 252.0);
// Clear demo data
shapeWithPieChart.getChart().getSeries().clear();

ChartSeries pieChartSeries = shapeWithPieChart.getChart().getSeries().add("Aspose Test Series",
        new String[]{"Word", "PDF", "Excel"},
        new double[]{2.7, 3.2, 0.8});

// Set default values for the pie chart data labels
ChartDataLabelCollection pieChartDataLabels = pieChartSeries.getDataLabels();
pieChartDataLabels.setShowLeaderLines(true);
pieChartDataLabels.setShowLegendKey(true);
pieChartDataLabels.setShowPercentage(true);
pieChartDataLabels.setShowValue(true);

doc.save(getArtifactsDir() + "Charts.WorkWithChartDataLabelCollection.docx");

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<ChartDataLabeliterator()
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());
    }
}

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.