java.lang.Object
com.aspose.words.ChartDataLabelCollection
public class ChartDataLabelCollection
Example:
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 | ||
|---|---|---|
int | getCount() | |
|
Returns the number of |
||
ChartNumberFormat | getNumberFormat() | |
|
Gets an |
||
java.lang.String | getSeparator() | |
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. | ||
boolean | getShowBubbleSize() | |
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. | ||
boolean | getShowCategoryName() | |
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. | ||
boolean | getShowDataLabelsRange() | |
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. | ||
boolean | getShowLeaderLines() | |
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. | ||
boolean | getShowLegendKey() | |
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. | ||
boolean | getShowPercentage() | |
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. | ||
boolean | getShowSeriesName() | |
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. | ||
boolean | getShowValue() | |
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. | ||
ChartDataLabel | get(int index) | |
|
Returns |
||
| Method Summary | ||
|---|---|---|
ChartDataLabel | add(int index) | |
|
Adds new |
||
void | clear() | |
|
Removes all |
||
java.util.Iterator<ChartDataLabel> | iterator() | |
| Returns an enumerator object. | ||
void | removeAt(int index) | |
|
Removes a |
||
| Property Getters/Setters Detail |
|---|
getCount | |
public int getCount() | |
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() | |
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) | |
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) | |
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) | |
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) | |
getShowLeaderLines/setShowLeaderLines | |
public boolean getShowLeaderLines() / public void setShowLeaderLines(boolean value) | |
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
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) | |
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) | |
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) | |
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) | |
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) | |
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) | |
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() | |
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() | |
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) | |
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());
}
}