com.aspose.words
Class ChartDataLabel

java.lang.Object
    extended by com.aspose.words.ChartDataLabel
All Implemented Interfaces:
java.lang.Cloneable

public class ChartDataLabel 
extends java.lang.Object

Represents data label on a chart point or trendline. On a series, the ChartDataLabel object is a member of the ChartDataLabelCollection. The ChartDataLabelCollection contains a ChartDataLabel object for each point.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

Property Getters/Setters Summary
intgetIndex()
           Specifies the index of the containing element. This index shall determine which of the parent's children collection this element applies to. Default value is 0.
booleanisHidden()
voidisHidden(boolean value)
           Gets/sets a flag indicating whether this label is hidden. The default value is false.
booleanisVisible()
           Returns true if this data label has something to display.
ChartNumberFormatgetNumberFormat()
           Returns number format of the parent element.
java.lang.StringgetSeparator()
voidsetSeparator(java.lang.String value)
           Gets or sets string separator used for the data labels on a chart. The default is a comma, except for pie charts showing only category name and percentage, when a line break shall be used instead.
booleangetShowBubbleSize()
voidsetShowBubbleSize(boolean value)
           Allows to specify if bubble size is to be displayed for the data labels on a chart. Applies only to Bubble charts. Default value is false.
booleangetShowCategoryName()
voidsetShowCategoryName(boolean value)
           Allows to specify if category name is to be displayed for the data labels on a chart. Default value is false.
booleangetShowDataLabelsRange()
voidsetShowDataLabelsRange(boolean value)
           Allows to specify if values from data labels range to be displayed in the data labels. Default value is false.
booleangetShowLeaderLines()
voidsetShowLeaderLines(boolean value)
           Allows to specify if data label leader lines need be shown. Default value is false.
booleangetShowLegendKey()
voidsetShowLegendKey(boolean value)
           Allows to specify if legend key is to be displayed for the data labels on a chart. Default value is false.
booleangetShowPercentage()
voidsetShowPercentage(boolean value)
           Allows to specify if percentage value is to be displayed for the data labels on a chart. Default value is false.
booleangetShowSeriesName()
voidsetShowSeriesName(boolean value)
           Returns or sets a Boolean to indicate the series name display behavior for the data labels on a chart. True to show the series name. False to hide. By default false.
booleangetShowValue()
voidsetShowValue(boolean value)
           Allows to specify if values are to be displayed in the data labels. Default value is false.
 
Method Summary
voidclearFormat()
           Clears format of this data label. The properties are set to the default values defined in the parent data label collection.
 

Property Getters/Setters Detail

getIndex

public int getIndex()
Specifies the index of the containing element. This index shall determine which of the parent's children collection this element applies to. Default value is 0.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

isHidden/isHidden

public boolean isHidden() / public void isHidden(boolean value)
Gets/sets a flag indicating whether this label is hidden. The default value is false.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

isVisible

public boolean isVisible()
Returns true if this data label has something to display.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

getNumberFormat

public ChartNumberFormat getNumberFormat()
Returns number format of the parent element.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

getSeparator/setSeparator

public java.lang.String getSeparator() / public void setSeparator(java.lang.String value)
Gets or sets string separator used for the data labels on a chart. The default is a comma, except for pie charts showing only category name and percentage, when a line break shall be used instead.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

getShowBubbleSize/setShowBubbleSize

public boolean getShowBubbleSize() / public void setShowBubbleSize(boolean value)
Allows to specify if bubble size is to be displayed for the data labels on a chart. Applies only to Bubble charts. Default value is false.

Example:

Shows how to use 3D effects with bubble charts.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert a bubble chart with 3D effects on each bubble
Shape shape = builder.insertChart(ChartType.BUBBLE_3_D, 500.0, 350.0);
Chart chart = shape.getChart();

Assert.assertTrue(chart.getSeries().get(0).getBubble3D());

// Apply a data label to each bubble that displays the size of its bubble
for (int i = 0; i < 3; i++) {
    chart.getSeries().get(0).hasDataLabels(true);
    ChartDataLabel cdl = chart.getSeries().get(0).getDataLabels().get(i);
    cdl.setShowBubbleSize(true);
}

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

getShowCategoryName/setShowCategoryName

public boolean getShowCategoryName() / public void setShowCategoryName(boolean value)
Allows to specify if category name is to be displayed for the data labels on a chart. Default value is false.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

getShowDataLabelsRange/setShowDataLabelsRange

public boolean getShowDataLabelsRange() / public void setShowDataLabelsRange(boolean value)
Allows to specify if values from data labels range to be displayed in the data labels. Default value is false.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

getShowLeaderLines/setShowLeaderLines

public boolean getShowLeaderLines() / public void setShowLeaderLines(boolean value)
Allows to specify if data label leader lines need be shown. Default value is false. Applies to Pie charts only. Leader lines create a visual connection between a data label and its corresponding data point.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

getShowLegendKey/setShowLegendKey

public boolean getShowLegendKey() / public void setShowLegendKey(boolean value)
Allows to specify if legend key is to be displayed for the data labels on a chart. Default value is false.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

getShowPercentage/setShowPercentage

public boolean getShowPercentage() / public void setShowPercentage(boolean value)
Allows to specify if percentage value is to be displayed for the data labels on a chart. Default value is false.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

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 on a chart. True to show the series name. False to hide. By default false.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

getShowValue/setShowValue

public boolean getShowValue() / public void setShowValue(boolean value)
Allows to specify if values are to be displayed in the data labels. Default value is false.

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().get(2).clearFormat();

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

    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 static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
    for (int i = 0; i < labelsCount; i++) {
        series.hasDataLabels(true);
        ChartDataLabel label = series.getDataLabels().get(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);
        label.isHidden(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());
        Assert.assertFalse(label.isHidden());
    }
}

Method Detail

clearFormat

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

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