public class ChartDataLabel
extends java.lang.Object
implements java.lang.Cloneable
To learn more, visit the Working with Charts documentation article.
Remarks:
On a series, the ChartDataLabel object is a member of the ChartDataLabelCollection. The ChartDataLabelCollection contains a ChartDataLabel object for each point.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
clearFormat()
Clears format of this data label.
|
java.lang.Object |
fetchSpecialDefaultRunPropertyValue(int key) |
java.lang.String |
generateItemText() |
Font |
getFont()
Provides access to the font formatting of this data label.
|
ChartFormat |
getFormat()
Provides access to fill and line formatting of the data label.
|
int |
getIndex()
Specifies the index of the containing element.
|
double |
getLeft()
Gets the distance of the data label in points from the left edge of the chart or from the position specified by its
getPosition() / setPosition(int) property, depending on the value of the getLeftMode() / setLeftMode(int) property. |
int |
getLeftMode()
Gets the interpretation mode of the
getLeft() / setLeft(double) property value: whether it sets the location of the data label from the left edge of the chart of from the position specified by its getPosition() / setPosition(int) property. |
ChartNumberFormat |
getNumberFormat()
Returns number format of the parent element.
|
int |
getOrientation()
Gets the orientation of the label text.
|
int |
getPosition()
Gets the position of the data label.
|
java.lang.Object |
getRelativePropertyValue(int key,
java.lang.Object value) |
int |
getRotation()
Gets the rotation of the label in degrees.
|
java.lang.String |
getSeparator()
Gets string separator used for the data labels on a chart.
|
int |
getShapeType() |
boolean |
getShowBubbleSize()
Allows to specify if bubble size is to be displayed for the data labels on a chart.
|
boolean |
getShowCategoryName()
Allows to specify if category name is to be displayed for the data labels on a chart.
|
boolean |
getShowDataLabelsRange()
Allows to specify if values from data labels range to be displayed in the data labels.
|
boolean |
getShowLeaderLines()
Allows to specify if data label leader lines need be shown.
|
boolean |
getShowLegendKey()
Allows to specify if legend key is to be displayed for the data labels on a chart.
|
boolean |
getShowPercentage()
Allows to specify if percentage value is to be displayed for the data labels on a chart.
|
boolean |
getShowSeriesName()
Gets a Boolean to indicate the series name display behavior for the data labels on a chart.
|
boolean |
getShowValue()
Allows to specify if values are to be displayed in the data labels.
|
double |
getTop()
Gets the distance of the data label in points from the top edge of the chart or from the position specified by its
getPosition() / setPosition(int) property, depending on the value of the getTopMode() / setTopMode(int) property. |
int |
getTopMode()
Gets the interpretation mode of the
getTop() / setTop(double) property value: whether it sets the location of the data label from the top edge of the chart of from the position specified by its getPosition() / setPosition(int) property. |
boolean |
isFillSupported() |
boolean |
isFormatDefined() |
boolean |
isHidden()
Gets/sets a flag indicating whether this label is hidden.
|
void |
isHidden(boolean value)
Gets/sets a flag indicating whether this label is hidden.
|
boolean |
isInherited() |
boolean |
isVisible()
Returns
true if this data label has something to display. |
void |
materializeSpPr() |
protected java.lang.Object |
memberwiseClone() |
void |
setLeft(double value)
Sets the distance of the data label in points from the left edge of the chart or from the position specified by its
getPosition() / setPosition(int) property, depending on the value of the getLeftMode() / setLeftMode(int) property. |
void |
setLeftMode(int value)
Sets the interpretation mode of the
getLeft() / setLeft(double) property value: whether it sets the location of the data label from the left edge of the chart of from the position specified by its getPosition() / setPosition(int) property. |
void |
setOrientation(int value)
Sets the orientation of the label text.
|
void |
setPosition(int value)
Sets the position of the data label.
|
void |
setRotation(int value)
Sets the rotation of the label in degrees.
|
void |
setSeparator(java.lang.String value)
Sets string separator used for the data labels on a chart.
|
void |
setShapeType(int value) |
void |
setShowBubbleSize(boolean value)
Allows to specify if bubble size is to be displayed for the data labels on a chart.
|
void |
setShowCategoryName(boolean value)
Allows to specify if category name is to be displayed for the data labels on a chart.
|
void |
setShowDataLabelsRange(boolean value)
Allows to specify if values from data labels range to be displayed in the data labels.
|
void |
setShowLeaderLines(boolean value)
Allows to specify if data label leader lines need be shown.
|
void |
setShowLegendKey(boolean value)
Allows to specify if legend key is to be displayed for the data labels on a chart.
|
void |
setShowPercentage(boolean value)
Allows to specify if percentage value is to be displayed for the data labels on a chart.
|
void |
setShowSeriesName(boolean value)
Sets a Boolean to indicate the series name display behavior for the data labels on a chart.
|
void |
setShowValue(boolean value)
Allows to specify if values are to be displayed in the data labels.
|
void |
setTop(double value)
Sets the distance of the data label in points from the top edge of the chart or from the position specified by its
getPosition() / setPosition(int) property, depending on the value of the getTopMode() / setTopMode(int) property. |
void |
setTopMode(int value)
Sets the interpretation mode of the
getTop() / setTop(double) property value: whether it sets the location of the data label from the top edge of the chart of from the position specified by its getPosition() / setPosition(int) property. |
public void clearFormat()
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
public void materializeSpPr()
public boolean isFillSupported()
public int getShapeType()
public void setShapeType(int value)
public boolean isFormatDefined()
public int getIndex()
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
int value.public boolean getShowCategoryName()
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
boolean value.public void setShowCategoryName(boolean value)
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - The corresponding boolean value.public boolean getShowBubbleSize()
false.
Examples:
Shows how to use 3D effects with bubble charts.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.BUBBLE_3_D, 500.0, 350.0);
Chart chart = shape.getChart();
Assert.assertEquals(1, chart.getSeries().getCount());
Assert.assertEquals("Y-Values", chart.getSeries().get(0).getName());
Assert.assertTrue(chart.getSeries().get(0).getBubble3D());
// Apply a data label to each bubble that displays its diameter.
for (int i = 0; i < 3; i++) {
chart.getSeries().get(0).hasDataLabels(true);
ChartDataLabel cdl = chart.getSeries().get(0).getDataLabels().get(i);
chart.getSeries().get(0).getDataLabels().get(i).getFont().setSize(12.0);
cdl.setShowBubbleSize(true);
}
doc.save(getArtifactsDir() + "Charts.Bubble3D.docx");
boolean value.public void setShowBubbleSize(boolean value)
false.
Examples:
Shows how to use 3D effects with bubble charts.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.BUBBLE_3_D, 500.0, 350.0);
Chart chart = shape.getChart();
Assert.assertEquals(1, chart.getSeries().getCount());
Assert.assertEquals("Y-Values", chart.getSeries().get(0).getName());
Assert.assertTrue(chart.getSeries().get(0).getBubble3D());
// Apply a data label to each bubble that displays its diameter.
for (int i = 0; i < 3; i++) {
chart.getSeries().get(0).hasDataLabels(true);
ChartDataLabel cdl = chart.getSeries().get(0).getDataLabels().get(i);
chart.getSeries().get(0).getDataLabels().get(i).getFont().setSize(12.0);
cdl.setShowBubbleSize(true);
}
doc.save(getArtifactsDir() + "Charts.Bubble3D.docx");
value - The corresponding boolean value.public boolean getShowLegendKey()
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
boolean value.public void setShowLegendKey(boolean value)
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - The corresponding boolean value.public boolean getShowPercentage()
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
boolean value.public void setShowPercentage(boolean value)
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - The corresponding boolean value.public boolean getShowSeriesName()
true to show the series name; false to hide. By default false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
public void setShowSeriesName(boolean value)
true to show the series name; false to hide. By default false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - A Boolean to indicate the series name display behavior for the data labels on a chart.public boolean getShowValue()
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
boolean value.public void setShowValue(boolean value)
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - The corresponding boolean value.public boolean getShowLeaderLines()
false.
Remarks:
Applies to Pie charts only. Leader lines create a visual connection between a data label and its corresponding data point.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
boolean value.public void setShowLeaderLines(boolean value)
false.
Remarks:
Applies to Pie charts only. Leader lines create a visual connection between a data label and its corresponding data point.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - The corresponding boolean value.public boolean getShowDataLabelsRange()
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
boolean value.public void setShowDataLabelsRange(boolean value)
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - The corresponding boolean value.public java.lang.String getSeparator()
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
public void setSeparator(java.lang.String value)
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - String separator used for the data labels on a chart.public int getOrientation()
Remarks:
The default value is ShapeTextOrientation.HORIZONTAL.
Examples:
Shows how to change orientation and rotation for data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
ChartSeries series = shape.getChart().getSeries().get(0);
ChartDataLabelCollection dataLabels = series.getDataLabels();
// Show data labels.
series.hasDataLabels(true);
dataLabels.setShowValue(true);
dataLabels.setShowCategoryName(true);
// Define data label shape.
dataLabels.getFormat().setShapeType(ChartShapeType.UP_ARROW);
dataLabels.getFormat().getStroke().getFill().solid(Color.blue);
// Set data label orientation and rotation for the entire series.
dataLabels.setOrientation(ShapeTextOrientation.VERTICAL_FAR_EAST);
dataLabels.setRotation(-45);
// Change orientation and rotation of the first data label.
dataLabels.get(0).setOrientation(ShapeTextOrientation.HORIZONTAL);
dataLabels.get(0).setRotation(45);
doc.save(getArtifactsDir() + "Charts.LabelOrientationRotation.docx");
ShapeTextOrientation constants.public void setOrientation(int value)
Remarks:
The default value is ShapeTextOrientation.HORIZONTAL.
Examples:
Shows how to change orientation and rotation for data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
ChartSeries series = shape.getChart().getSeries().get(0);
ChartDataLabelCollection dataLabels = series.getDataLabels();
// Show data labels.
series.hasDataLabels(true);
dataLabels.setShowValue(true);
dataLabels.setShowCategoryName(true);
// Define data label shape.
dataLabels.getFormat().setShapeType(ChartShapeType.UP_ARROW);
dataLabels.getFormat().getStroke().getFill().solid(Color.blue);
// Set data label orientation and rotation for the entire series.
dataLabels.setOrientation(ShapeTextOrientation.VERTICAL_FAR_EAST);
dataLabels.setRotation(-45);
// Change orientation and rotation of the first data label.
dataLabels.get(0).setOrientation(ShapeTextOrientation.HORIZONTAL);
dataLabels.get(0).setRotation(45);
doc.save(getArtifactsDir() + "Charts.LabelOrientationRotation.docx");
value - The orientation of the label text. The value must be one of ShapeTextOrientation constants.public int getRotation()
Remarks:
The range of acceptable values is from -180 to 180 inclusive. The default value is 0.
If the getOrientation() / setOrientation(int) value is ShapeTextOrientation.HORIZONTAL, the label shape, if it exists, is rotated along with the label text. Otherwise, only the label text is rotated.
Examples:
Shows how to change orientation and rotation for data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
ChartSeries series = shape.getChart().getSeries().get(0);
ChartDataLabelCollection dataLabels = series.getDataLabels();
// Show data labels.
series.hasDataLabels(true);
dataLabels.setShowValue(true);
dataLabels.setShowCategoryName(true);
// Define data label shape.
dataLabels.getFormat().setShapeType(ChartShapeType.UP_ARROW);
dataLabels.getFormat().getStroke().getFill().solid(Color.blue);
// Set data label orientation and rotation for the entire series.
dataLabels.setOrientation(ShapeTextOrientation.VERTICAL_FAR_EAST);
dataLabels.setRotation(-45);
// Change orientation and rotation of the first data label.
dataLabels.get(0).setOrientation(ShapeTextOrientation.HORIZONTAL);
dataLabels.get(0).setRotation(45);
doc.save(getArtifactsDir() + "Charts.LabelOrientationRotation.docx");
public void setRotation(int value)
Remarks:
The range of acceptable values is from -180 to 180 inclusive. The default value is 0.
If the getOrientation() / setOrientation(int) value is ShapeTextOrientation.HORIZONTAL, the label shape, if it exists, is rotated along with the label text. Otherwise, only the label text is rotated.
Examples:
Shows how to change orientation and rotation for data labels.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
ChartSeries series = shape.getChart().getSeries().get(0);
ChartDataLabelCollection dataLabels = series.getDataLabels();
// Show data labels.
series.hasDataLabels(true);
dataLabels.setShowValue(true);
dataLabels.setShowCategoryName(true);
// Define data label shape.
dataLabels.getFormat().setShapeType(ChartShapeType.UP_ARROW);
dataLabels.getFormat().getStroke().getFill().solid(Color.blue);
// Set data label orientation and rotation for the entire series.
dataLabels.setOrientation(ShapeTextOrientation.VERTICAL_FAR_EAST);
dataLabels.setRotation(-45);
// Change orientation and rotation of the first data label.
dataLabels.get(0).setOrientation(ShapeTextOrientation.HORIZONTAL);
dataLabels.get(0).setRotation(45);
doc.save(getArtifactsDir() + "Charts.LabelOrientationRotation.docx");
value - The rotation of the label in degrees.public boolean isVisible()
true if this data label has something to display.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
true if this data label has something to display.public ChartNumberFormat getNumberFormat()
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
public boolean isHidden()
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
boolean value.public void isHidden(boolean value)
false.
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
value - The corresponding boolean value.public Font getFont()
Examples:
Shows how to use 3D effects with bubble charts.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.BUBBLE_3_D, 500.0, 350.0);
Chart chart = shape.getChart();
Assert.assertEquals(1, chart.getSeries().getCount());
Assert.assertEquals("Y-Values", chart.getSeries().get(0).getName());
Assert.assertTrue(chart.getSeries().get(0).getBubble3D());
// Apply a data label to each bubble that displays its diameter.
for (int i = 0; i < 3; i++) {
chart.getSeries().get(0).hasDataLabels(true);
ChartDataLabel cdl = chart.getSeries().get(0).getDataLabels().get(i);
chart.getSeries().get(0).getDataLabels().get(i).getFont().setSize(12.0);
cdl.setShowBubbleSize(true);
}
doc.save(getArtifactsDir() + "Charts.Bubble3D.docx");
Font value.public ChartFormat getFormat()
Examples:
Shows how to apply labels to data points in a line chart.
public void dataLabels() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape chartShape = builder.insertChart(ChartType.LINE, 400.0, 300.0);
Chart chart = chartShape.getChart();
Assert.assertEquals(3, chart.getSeries().getCount());
Assert.assertEquals("Series 1", chart.getSeries().get(0).getName());
Assert.assertEquals("Series 2", chart.getSeries().get(1).getName());
Assert.assertEquals("Series 3", chart.getSeries().get(2).getName());
// Apply data labels to every series in the chart.
// These labels will appear next to each data point in the graph and display its value.
for (ChartSeries series : chart.getSeries()) {
applyDataLabels(series, 4, "000.0", ", ");
Assert.assertEquals(series.getDataLabels().getCount(), 4);
}
// Change the separator string for every data label in a series.
Iterator<ChartDataLabel> enumerator = chart.getSeries().get(0).getDataLabels().iterator();
while (enumerator.hasNext()) {
Assert.assertEquals(enumerator.next().getSeparator(), ", ");
enumerator.next().setSeparator(" & ");
}
ChartDataLabel dataLabel = chart.getSeries().get(1).getDataLabels().get(2);
dataLabel.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can remove data labels individually.
dataLabel.clearFormat();
// We can also strip an entire series of its data labels at once.
chart.getSeries().get(2).getDataLabels().clearFormat();
doc.save(getArtifactsDir() + "Charts.DataLabels.docx");
}
/// <summary>
/// Apply data labels with custom number format and separator to several data points in a series.
/// </summary>
private static void applyDataLabels(ChartSeries series, int labelsCount, String numberFormat, String separator) {
series.hasDataLabels(true);
series.setExplosion(40);
for (int i = 0; i < labelsCount; i++) {
Assert.assertFalse(series.getDataLabels().get(i).isVisible());
series.getDataLabels().get(i).setShowCategoryName(true);
series.getDataLabels().get(i).setShowSeriesName(true);
series.getDataLabels().get(i).setShowValue(true);
series.getDataLabels().get(i).setShowLeaderLines(true);
series.getDataLabels().get(i).setShowLegendKey(true);
series.getDataLabels().get(i).setShowPercentage(false);
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
series.getDataLabels().get(i).getNumberFormat().setFormatCode(numberFormat);
series.getDataLabels().get(i).setSeparator(separator);
Assert.assertFalse(series.getDataLabels().get(i).getShowDataLabelsRange());
Assert.assertTrue(series.getDataLabels().get(i).isVisible());
Assert.assertFalse(series.getDataLabels().get(i).isHidden());
}
}
ChartFormat value.public double getLeft()
getPosition() / setPosition(int) property, depending on the value of the getLeftMode() / setLeftMode(int) property.
Remarks:
The value of the property changes proportionally if the chart shape is resized.
The property cannot be set in a Word 2016 chart.
Examples:
Shows how to place data labels of doughnut chart outside doughnut.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final int CHART_WIDTH = 432;
final int CHART_HEIGHT = 252;
Shape shape = builder.insertChart(ChartType.DOUGHNUT, CHART_WIDTH, CHART_HEIGHT);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Hide the legend.
chart.getLegend().setPosition(LegendPosition.NONE);
// Generate data.
final int DATA_LENGTH = 20;
double totalValue = 0.0;
String[] categories = new String[DATA_LENGTH];
double[] values = new double[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++)
{
categories[i] = MessageFormat.format("Category {0}", i);
values[i] = DATA_LENGTH - i;
totalValue += values[i];
}
ChartSeries series = seriesColl.add("Series 1", categories, values);
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.setShowLeaderLines(true);
// The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top
// properties around a circle outside of the chart doughnut.
// The origin is in the upper left corner of the chart.
final double TITLE_AREA_HEIGHT = 25.5; // This can be calculated using title text and font.
final double DOUGHNUT_CENTER_Y = TITLE_AREA_HEIGHT + (CHART_HEIGHT - TITLE_AREA_HEIGHT) / 2.0;
final double DOUGHNUT_CENTER_X = CHART_WIDTH / 2d;
final double LABEL_HEIGHT = 16.5; // This can be calculated using label font.
final double ONE_CHAR_LABEL_WIDTH = 12.75; // This can be calculated for each label using its text and font.
final double TWO_CHAR_LABEL_WIDTH = 17.25; // This can be calculated for each label using its text and font.
final double Y_MARGIN = 0.75;
final double LABEL_MARGIN = 1.5;
final double LABEL_CIRCLE_RADIUS = CHART_HEIGHT - DOUGHNUT_CENTER_Y - Y_MARGIN - LABEL_HEIGHT / 2.0;
// Because the data points start at the top, the X coordinates used in the Left and Top properties of
// the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2.
double totalAngle = -Math.PI / 2f;
ChartDataLabel previousLabel = null;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
ChartDataLabel dataLabel = dataLabels.get(i);
double value = series.getYValues().get(i).getDoubleValue();
double labelWidth;
if (value < 10)
labelWidth = ONE_CHAR_LABEL_WIDTH;
else
labelWidth = TWO_CHAR_LABEL_WIDTH;
double labelSegmentAngle = value / totalValue * 2.0 * Math.PI;
double labelAngle = labelSegmentAngle / 2.0 + totalAngle;
double labelCenterX = LABEL_CIRCLE_RADIUS * Math.cos(labelAngle) + DOUGHNUT_CENTER_X;
double labelCenterY = LABEL_CIRCLE_RADIUS * Math.sin(labelAngle) + DOUGHNUT_CENTER_Y;
double labelLeft = labelCenterX - labelWidth / 2.0;
double labelTop = labelCenterY - LABEL_HEIGHT / 2.0;
// If the current data label overlaps other labels, move it horizontally.
if ((previousLabel != null) &&
(Math.abs(previousLabel.getTop() - labelTop) < LABEL_HEIGHT) &&
(Math.abs(previousLabel.getLeft() - labelLeft) < labelWidth))
{
// Move right on the top, left on the bottom.
boolean isOnTop = (totalAngle < 0) || (totalAngle >= Math.PI);
int factor;
if (isOnTop)
factor = 1;
else
factor = -1;
labelLeft = previousLabel.getLeft() + labelWidth * factor + LABEL_MARGIN;
}
dataLabel.setLeft(labelLeft);
dataLabel.setLeftMode(ChartDataLabelLocationMode.ABSOLUTE);
dataLabel.setTop(labelTop);
dataLabel.setTopMode(ChartDataLabelLocationMode.ABSOLUTE);
totalAngle += labelSegmentAngle;
previousLabel = dataLabel;
}
doc.save(getArtifactsDir() + "Charts.DoughnutChartLabelPosition.docx");
getPosition() / setPosition(int) property, depending on the value of the getLeftMode() / setLeftMode(int) property.public void setLeft(double value)
getPosition() / setPosition(int) property, depending on the value of the getLeftMode() / setLeftMode(int) property.
Remarks:
The value of the property changes proportionally if the chart shape is resized.
The property cannot be set in a Word 2016 chart.
Examples:
Shows how to place data labels of doughnut chart outside doughnut.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final int CHART_WIDTH = 432;
final int CHART_HEIGHT = 252;
Shape shape = builder.insertChart(ChartType.DOUGHNUT, CHART_WIDTH, CHART_HEIGHT);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Hide the legend.
chart.getLegend().setPosition(LegendPosition.NONE);
// Generate data.
final int DATA_LENGTH = 20;
double totalValue = 0.0;
String[] categories = new String[DATA_LENGTH];
double[] values = new double[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++)
{
categories[i] = MessageFormat.format("Category {0}", i);
values[i] = DATA_LENGTH - i;
totalValue += values[i];
}
ChartSeries series = seriesColl.add("Series 1", categories, values);
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.setShowLeaderLines(true);
// The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top
// properties around a circle outside of the chart doughnut.
// The origin is in the upper left corner of the chart.
final double TITLE_AREA_HEIGHT = 25.5; // This can be calculated using title text and font.
final double DOUGHNUT_CENTER_Y = TITLE_AREA_HEIGHT + (CHART_HEIGHT - TITLE_AREA_HEIGHT) / 2.0;
final double DOUGHNUT_CENTER_X = CHART_WIDTH / 2d;
final double LABEL_HEIGHT = 16.5; // This can be calculated using label font.
final double ONE_CHAR_LABEL_WIDTH = 12.75; // This can be calculated for each label using its text and font.
final double TWO_CHAR_LABEL_WIDTH = 17.25; // This can be calculated for each label using its text and font.
final double Y_MARGIN = 0.75;
final double LABEL_MARGIN = 1.5;
final double LABEL_CIRCLE_RADIUS = CHART_HEIGHT - DOUGHNUT_CENTER_Y - Y_MARGIN - LABEL_HEIGHT / 2.0;
// Because the data points start at the top, the X coordinates used in the Left and Top properties of
// the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2.
double totalAngle = -Math.PI / 2f;
ChartDataLabel previousLabel = null;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
ChartDataLabel dataLabel = dataLabels.get(i);
double value = series.getYValues().get(i).getDoubleValue();
double labelWidth;
if (value < 10)
labelWidth = ONE_CHAR_LABEL_WIDTH;
else
labelWidth = TWO_CHAR_LABEL_WIDTH;
double labelSegmentAngle = value / totalValue * 2.0 * Math.PI;
double labelAngle = labelSegmentAngle / 2.0 + totalAngle;
double labelCenterX = LABEL_CIRCLE_RADIUS * Math.cos(labelAngle) + DOUGHNUT_CENTER_X;
double labelCenterY = LABEL_CIRCLE_RADIUS * Math.sin(labelAngle) + DOUGHNUT_CENTER_Y;
double labelLeft = labelCenterX - labelWidth / 2.0;
double labelTop = labelCenterY - LABEL_HEIGHT / 2.0;
// If the current data label overlaps other labels, move it horizontally.
if ((previousLabel != null) &&
(Math.abs(previousLabel.getTop() - labelTop) < LABEL_HEIGHT) &&
(Math.abs(previousLabel.getLeft() - labelLeft) < labelWidth))
{
// Move right on the top, left on the bottom.
boolean isOnTop = (totalAngle < 0) || (totalAngle >= Math.PI);
int factor;
if (isOnTop)
factor = 1;
else
factor = -1;
labelLeft = previousLabel.getLeft() + labelWidth * factor + LABEL_MARGIN;
}
dataLabel.setLeft(labelLeft);
dataLabel.setLeftMode(ChartDataLabelLocationMode.ABSOLUTE);
dataLabel.setTop(labelTop);
dataLabel.setTopMode(ChartDataLabelLocationMode.ABSOLUTE);
totalAngle += labelSegmentAngle;
previousLabel = dataLabel;
}
doc.save(getArtifactsDir() + "Charts.DoughnutChartLabelPosition.docx");
value - The distance of the data label in points from the left edge of the chart or from the position specified by its getPosition() / setPosition(int) property, depending on the value of the getLeftMode() / setLeftMode(int) property.public int getLeftMode()
getLeft() / setLeft(double) property value: whether it sets the location of the data label from the left edge of the chart of from the position specified by its getPosition() / setPosition(int) property.
Remarks:
The property cannot be set in a Word 2016 chart.
Examples:
Shows how to place data labels of doughnut chart outside doughnut.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final int CHART_WIDTH = 432;
final int CHART_HEIGHT = 252;
Shape shape = builder.insertChart(ChartType.DOUGHNUT, CHART_WIDTH, CHART_HEIGHT);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Hide the legend.
chart.getLegend().setPosition(LegendPosition.NONE);
// Generate data.
final int DATA_LENGTH = 20;
double totalValue = 0.0;
String[] categories = new String[DATA_LENGTH];
double[] values = new double[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++)
{
categories[i] = MessageFormat.format("Category {0}", i);
values[i] = DATA_LENGTH - i;
totalValue += values[i];
}
ChartSeries series = seriesColl.add("Series 1", categories, values);
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.setShowLeaderLines(true);
// The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top
// properties around a circle outside of the chart doughnut.
// The origin is in the upper left corner of the chart.
final double TITLE_AREA_HEIGHT = 25.5; // This can be calculated using title text and font.
final double DOUGHNUT_CENTER_Y = TITLE_AREA_HEIGHT + (CHART_HEIGHT - TITLE_AREA_HEIGHT) / 2.0;
final double DOUGHNUT_CENTER_X = CHART_WIDTH / 2d;
final double LABEL_HEIGHT = 16.5; // This can be calculated using label font.
final double ONE_CHAR_LABEL_WIDTH = 12.75; // This can be calculated for each label using its text and font.
final double TWO_CHAR_LABEL_WIDTH = 17.25; // This can be calculated for each label using its text and font.
final double Y_MARGIN = 0.75;
final double LABEL_MARGIN = 1.5;
final double LABEL_CIRCLE_RADIUS = CHART_HEIGHT - DOUGHNUT_CENTER_Y - Y_MARGIN - LABEL_HEIGHT / 2.0;
// Because the data points start at the top, the X coordinates used in the Left and Top properties of
// the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2.
double totalAngle = -Math.PI / 2f;
ChartDataLabel previousLabel = null;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
ChartDataLabel dataLabel = dataLabels.get(i);
double value = series.getYValues().get(i).getDoubleValue();
double labelWidth;
if (value < 10)
labelWidth = ONE_CHAR_LABEL_WIDTH;
else
labelWidth = TWO_CHAR_LABEL_WIDTH;
double labelSegmentAngle = value / totalValue * 2.0 * Math.PI;
double labelAngle = labelSegmentAngle / 2.0 + totalAngle;
double labelCenterX = LABEL_CIRCLE_RADIUS * Math.cos(labelAngle) + DOUGHNUT_CENTER_X;
double labelCenterY = LABEL_CIRCLE_RADIUS * Math.sin(labelAngle) + DOUGHNUT_CENTER_Y;
double labelLeft = labelCenterX - labelWidth / 2.0;
double labelTop = labelCenterY - LABEL_HEIGHT / 2.0;
// If the current data label overlaps other labels, move it horizontally.
if ((previousLabel != null) &&
(Math.abs(previousLabel.getTop() - labelTop) < LABEL_HEIGHT) &&
(Math.abs(previousLabel.getLeft() - labelLeft) < labelWidth))
{
// Move right on the top, left on the bottom.
boolean isOnTop = (totalAngle < 0) || (totalAngle >= Math.PI);
int factor;
if (isOnTop)
factor = 1;
else
factor = -1;
labelLeft = previousLabel.getLeft() + labelWidth * factor + LABEL_MARGIN;
}
dataLabel.setLeft(labelLeft);
dataLabel.setLeftMode(ChartDataLabelLocationMode.ABSOLUTE);
dataLabel.setTop(labelTop);
dataLabel.setTopMode(ChartDataLabelLocationMode.ABSOLUTE);
totalAngle += labelSegmentAngle;
previousLabel = dataLabel;
}
doc.save(getArtifactsDir() + "Charts.DoughnutChartLabelPosition.docx");
getLeft() / setLeft(double) property value: whether it sets the location of the data label from the left edge of the chart of from the position specified by its getPosition() / setPosition(int) property. The returned value is one of ChartDataLabelLocationMode constants.public void setLeftMode(int value)
getLeft() / setLeft(double) property value: whether it sets the location of the data label from the left edge of the chart of from the position specified by its getPosition() / setPosition(int) property.
Remarks:
The property cannot be set in a Word 2016 chart.
Examples:
Shows how to place data labels of doughnut chart outside doughnut.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final int CHART_WIDTH = 432;
final int CHART_HEIGHT = 252;
Shape shape = builder.insertChart(ChartType.DOUGHNUT, CHART_WIDTH, CHART_HEIGHT);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Hide the legend.
chart.getLegend().setPosition(LegendPosition.NONE);
// Generate data.
final int DATA_LENGTH = 20;
double totalValue = 0.0;
String[] categories = new String[DATA_LENGTH];
double[] values = new double[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++)
{
categories[i] = MessageFormat.format("Category {0}", i);
values[i] = DATA_LENGTH - i;
totalValue += values[i];
}
ChartSeries series = seriesColl.add("Series 1", categories, values);
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.setShowLeaderLines(true);
// The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top
// properties around a circle outside of the chart doughnut.
// The origin is in the upper left corner of the chart.
final double TITLE_AREA_HEIGHT = 25.5; // This can be calculated using title text and font.
final double DOUGHNUT_CENTER_Y = TITLE_AREA_HEIGHT + (CHART_HEIGHT - TITLE_AREA_HEIGHT) / 2.0;
final double DOUGHNUT_CENTER_X = CHART_WIDTH / 2d;
final double LABEL_HEIGHT = 16.5; // This can be calculated using label font.
final double ONE_CHAR_LABEL_WIDTH = 12.75; // This can be calculated for each label using its text and font.
final double TWO_CHAR_LABEL_WIDTH = 17.25; // This can be calculated for each label using its text and font.
final double Y_MARGIN = 0.75;
final double LABEL_MARGIN = 1.5;
final double LABEL_CIRCLE_RADIUS = CHART_HEIGHT - DOUGHNUT_CENTER_Y - Y_MARGIN - LABEL_HEIGHT / 2.0;
// Because the data points start at the top, the X coordinates used in the Left and Top properties of
// the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2.
double totalAngle = -Math.PI / 2f;
ChartDataLabel previousLabel = null;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
ChartDataLabel dataLabel = dataLabels.get(i);
double value = series.getYValues().get(i).getDoubleValue();
double labelWidth;
if (value < 10)
labelWidth = ONE_CHAR_LABEL_WIDTH;
else
labelWidth = TWO_CHAR_LABEL_WIDTH;
double labelSegmentAngle = value / totalValue * 2.0 * Math.PI;
double labelAngle = labelSegmentAngle / 2.0 + totalAngle;
double labelCenterX = LABEL_CIRCLE_RADIUS * Math.cos(labelAngle) + DOUGHNUT_CENTER_X;
double labelCenterY = LABEL_CIRCLE_RADIUS * Math.sin(labelAngle) + DOUGHNUT_CENTER_Y;
double labelLeft = labelCenterX - labelWidth / 2.0;
double labelTop = labelCenterY - LABEL_HEIGHT / 2.0;
// If the current data label overlaps other labels, move it horizontally.
if ((previousLabel != null) &&
(Math.abs(previousLabel.getTop() - labelTop) < LABEL_HEIGHT) &&
(Math.abs(previousLabel.getLeft() - labelLeft) < labelWidth))
{
// Move right on the top, left on the bottom.
boolean isOnTop = (totalAngle < 0) || (totalAngle >= Math.PI);
int factor;
if (isOnTop)
factor = 1;
else
factor = -1;
labelLeft = previousLabel.getLeft() + labelWidth * factor + LABEL_MARGIN;
}
dataLabel.setLeft(labelLeft);
dataLabel.setLeftMode(ChartDataLabelLocationMode.ABSOLUTE);
dataLabel.setTop(labelTop);
dataLabel.setTopMode(ChartDataLabelLocationMode.ABSOLUTE);
totalAngle += labelSegmentAngle;
previousLabel = dataLabel;
}
doc.save(getArtifactsDir() + "Charts.DoughnutChartLabelPosition.docx");
value - The interpretation mode of the getLeft() / setLeft(double) property value: whether it sets the location of the data label from the left edge of the chart of from the position specified by its getPosition() / setPosition(int) property. The value must be one of ChartDataLabelLocationMode constants.public double getTop()
getPosition() / setPosition(int) property, depending on the value of the getTopMode() / setTopMode(int) property.
Remarks:
The value of the property changes proportionally if the chart shape is resized.
The property cannot be set in a Word 2016 chart.
Examples:
Shows how to place data labels of doughnut chart outside doughnut.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final int CHART_WIDTH = 432;
final int CHART_HEIGHT = 252;
Shape shape = builder.insertChart(ChartType.DOUGHNUT, CHART_WIDTH, CHART_HEIGHT);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Hide the legend.
chart.getLegend().setPosition(LegendPosition.NONE);
// Generate data.
final int DATA_LENGTH = 20;
double totalValue = 0.0;
String[] categories = new String[DATA_LENGTH];
double[] values = new double[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++)
{
categories[i] = MessageFormat.format("Category {0}", i);
values[i] = DATA_LENGTH - i;
totalValue += values[i];
}
ChartSeries series = seriesColl.add("Series 1", categories, values);
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.setShowLeaderLines(true);
// The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top
// properties around a circle outside of the chart doughnut.
// The origin is in the upper left corner of the chart.
final double TITLE_AREA_HEIGHT = 25.5; // This can be calculated using title text and font.
final double DOUGHNUT_CENTER_Y = TITLE_AREA_HEIGHT + (CHART_HEIGHT - TITLE_AREA_HEIGHT) / 2.0;
final double DOUGHNUT_CENTER_X = CHART_WIDTH / 2d;
final double LABEL_HEIGHT = 16.5; // This can be calculated using label font.
final double ONE_CHAR_LABEL_WIDTH = 12.75; // This can be calculated for each label using its text and font.
final double TWO_CHAR_LABEL_WIDTH = 17.25; // This can be calculated for each label using its text and font.
final double Y_MARGIN = 0.75;
final double LABEL_MARGIN = 1.5;
final double LABEL_CIRCLE_RADIUS = CHART_HEIGHT - DOUGHNUT_CENTER_Y - Y_MARGIN - LABEL_HEIGHT / 2.0;
// Because the data points start at the top, the X coordinates used in the Left and Top properties of
// the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2.
double totalAngle = -Math.PI / 2f;
ChartDataLabel previousLabel = null;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
ChartDataLabel dataLabel = dataLabels.get(i);
double value = series.getYValues().get(i).getDoubleValue();
double labelWidth;
if (value < 10)
labelWidth = ONE_CHAR_LABEL_WIDTH;
else
labelWidth = TWO_CHAR_LABEL_WIDTH;
double labelSegmentAngle = value / totalValue * 2.0 * Math.PI;
double labelAngle = labelSegmentAngle / 2.0 + totalAngle;
double labelCenterX = LABEL_CIRCLE_RADIUS * Math.cos(labelAngle) + DOUGHNUT_CENTER_X;
double labelCenterY = LABEL_CIRCLE_RADIUS * Math.sin(labelAngle) + DOUGHNUT_CENTER_Y;
double labelLeft = labelCenterX - labelWidth / 2.0;
double labelTop = labelCenterY - LABEL_HEIGHT / 2.0;
// If the current data label overlaps other labels, move it horizontally.
if ((previousLabel != null) &&
(Math.abs(previousLabel.getTop() - labelTop) < LABEL_HEIGHT) &&
(Math.abs(previousLabel.getLeft() - labelLeft) < labelWidth))
{
// Move right on the top, left on the bottom.
boolean isOnTop = (totalAngle < 0) || (totalAngle >= Math.PI);
int factor;
if (isOnTop)
factor = 1;
else
factor = -1;
labelLeft = previousLabel.getLeft() + labelWidth * factor + LABEL_MARGIN;
}
dataLabel.setLeft(labelLeft);
dataLabel.setLeftMode(ChartDataLabelLocationMode.ABSOLUTE);
dataLabel.setTop(labelTop);
dataLabel.setTopMode(ChartDataLabelLocationMode.ABSOLUTE);
totalAngle += labelSegmentAngle;
previousLabel = dataLabel;
}
doc.save(getArtifactsDir() + "Charts.DoughnutChartLabelPosition.docx");
getPosition() / setPosition(int) property, depending on the value of the getTopMode() / setTopMode(int) property.public void setTop(double value)
getPosition() / setPosition(int) property, depending on the value of the getTopMode() / setTopMode(int) property.
Remarks:
The value of the property changes proportionally if the chart shape is resized.
The property cannot be set in a Word 2016 chart.
Examples:
Shows how to place data labels of doughnut chart outside doughnut.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final int CHART_WIDTH = 432;
final int CHART_HEIGHT = 252;
Shape shape = builder.insertChart(ChartType.DOUGHNUT, CHART_WIDTH, CHART_HEIGHT);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Hide the legend.
chart.getLegend().setPosition(LegendPosition.NONE);
// Generate data.
final int DATA_LENGTH = 20;
double totalValue = 0.0;
String[] categories = new String[DATA_LENGTH];
double[] values = new double[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++)
{
categories[i] = MessageFormat.format("Category {0}", i);
values[i] = DATA_LENGTH - i;
totalValue += values[i];
}
ChartSeries series = seriesColl.add("Series 1", categories, values);
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.setShowLeaderLines(true);
// The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top
// properties around a circle outside of the chart doughnut.
// The origin is in the upper left corner of the chart.
final double TITLE_AREA_HEIGHT = 25.5; // This can be calculated using title text and font.
final double DOUGHNUT_CENTER_Y = TITLE_AREA_HEIGHT + (CHART_HEIGHT - TITLE_AREA_HEIGHT) / 2.0;
final double DOUGHNUT_CENTER_X = CHART_WIDTH / 2d;
final double LABEL_HEIGHT = 16.5; // This can be calculated using label font.
final double ONE_CHAR_LABEL_WIDTH = 12.75; // This can be calculated for each label using its text and font.
final double TWO_CHAR_LABEL_WIDTH = 17.25; // This can be calculated for each label using its text and font.
final double Y_MARGIN = 0.75;
final double LABEL_MARGIN = 1.5;
final double LABEL_CIRCLE_RADIUS = CHART_HEIGHT - DOUGHNUT_CENTER_Y - Y_MARGIN - LABEL_HEIGHT / 2.0;
// Because the data points start at the top, the X coordinates used in the Left and Top properties of
// the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2.
double totalAngle = -Math.PI / 2f;
ChartDataLabel previousLabel = null;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
ChartDataLabel dataLabel = dataLabels.get(i);
double value = series.getYValues().get(i).getDoubleValue();
double labelWidth;
if (value < 10)
labelWidth = ONE_CHAR_LABEL_WIDTH;
else
labelWidth = TWO_CHAR_LABEL_WIDTH;
double labelSegmentAngle = value / totalValue * 2.0 * Math.PI;
double labelAngle = labelSegmentAngle / 2.0 + totalAngle;
double labelCenterX = LABEL_CIRCLE_RADIUS * Math.cos(labelAngle) + DOUGHNUT_CENTER_X;
double labelCenterY = LABEL_CIRCLE_RADIUS * Math.sin(labelAngle) + DOUGHNUT_CENTER_Y;
double labelLeft = labelCenterX - labelWidth / 2.0;
double labelTop = labelCenterY - LABEL_HEIGHT / 2.0;
// If the current data label overlaps other labels, move it horizontally.
if ((previousLabel != null) &&
(Math.abs(previousLabel.getTop() - labelTop) < LABEL_HEIGHT) &&
(Math.abs(previousLabel.getLeft() - labelLeft) < labelWidth))
{
// Move right on the top, left on the bottom.
boolean isOnTop = (totalAngle < 0) || (totalAngle >= Math.PI);
int factor;
if (isOnTop)
factor = 1;
else
factor = -1;
labelLeft = previousLabel.getLeft() + labelWidth * factor + LABEL_MARGIN;
}
dataLabel.setLeft(labelLeft);
dataLabel.setLeftMode(ChartDataLabelLocationMode.ABSOLUTE);
dataLabel.setTop(labelTop);
dataLabel.setTopMode(ChartDataLabelLocationMode.ABSOLUTE);
totalAngle += labelSegmentAngle;
previousLabel = dataLabel;
}
doc.save(getArtifactsDir() + "Charts.DoughnutChartLabelPosition.docx");
value - The distance of the data label in points from the top edge of the chart or from the position specified by its getPosition() / setPosition(int) property, depending on the value of the getTopMode() / setTopMode(int) property.public int getTopMode()
getTop() / setTop(double) property value: whether it sets the location of the data label from the top edge of the chart of from the position specified by its getPosition() / setPosition(int) property.
Remarks:
The property cannot be set in a Word 2016 chart.
Examples:
Shows how to place data labels of doughnut chart outside doughnut.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final int CHART_WIDTH = 432;
final int CHART_HEIGHT = 252;
Shape shape = builder.insertChart(ChartType.DOUGHNUT, CHART_WIDTH, CHART_HEIGHT);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Hide the legend.
chart.getLegend().setPosition(LegendPosition.NONE);
// Generate data.
final int DATA_LENGTH = 20;
double totalValue = 0.0;
String[] categories = new String[DATA_LENGTH];
double[] values = new double[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++)
{
categories[i] = MessageFormat.format("Category {0}", i);
values[i] = DATA_LENGTH - i;
totalValue += values[i];
}
ChartSeries series = seriesColl.add("Series 1", categories, values);
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.setShowLeaderLines(true);
// The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top
// properties around a circle outside of the chart doughnut.
// The origin is in the upper left corner of the chart.
final double TITLE_AREA_HEIGHT = 25.5; // This can be calculated using title text and font.
final double DOUGHNUT_CENTER_Y = TITLE_AREA_HEIGHT + (CHART_HEIGHT - TITLE_AREA_HEIGHT) / 2.0;
final double DOUGHNUT_CENTER_X = CHART_WIDTH / 2d;
final double LABEL_HEIGHT = 16.5; // This can be calculated using label font.
final double ONE_CHAR_LABEL_WIDTH = 12.75; // This can be calculated for each label using its text and font.
final double TWO_CHAR_LABEL_WIDTH = 17.25; // This can be calculated for each label using its text and font.
final double Y_MARGIN = 0.75;
final double LABEL_MARGIN = 1.5;
final double LABEL_CIRCLE_RADIUS = CHART_HEIGHT - DOUGHNUT_CENTER_Y - Y_MARGIN - LABEL_HEIGHT / 2.0;
// Because the data points start at the top, the X coordinates used in the Left and Top properties of
// the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2.
double totalAngle = -Math.PI / 2f;
ChartDataLabel previousLabel = null;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
ChartDataLabel dataLabel = dataLabels.get(i);
double value = series.getYValues().get(i).getDoubleValue();
double labelWidth;
if (value < 10)
labelWidth = ONE_CHAR_LABEL_WIDTH;
else
labelWidth = TWO_CHAR_LABEL_WIDTH;
double labelSegmentAngle = value / totalValue * 2.0 * Math.PI;
double labelAngle = labelSegmentAngle / 2.0 + totalAngle;
double labelCenterX = LABEL_CIRCLE_RADIUS * Math.cos(labelAngle) + DOUGHNUT_CENTER_X;
double labelCenterY = LABEL_CIRCLE_RADIUS * Math.sin(labelAngle) + DOUGHNUT_CENTER_Y;
double labelLeft = labelCenterX - labelWidth / 2.0;
double labelTop = labelCenterY - LABEL_HEIGHT / 2.0;
// If the current data label overlaps other labels, move it horizontally.
if ((previousLabel != null) &&
(Math.abs(previousLabel.getTop() - labelTop) < LABEL_HEIGHT) &&
(Math.abs(previousLabel.getLeft() - labelLeft) < labelWidth))
{
// Move right on the top, left on the bottom.
boolean isOnTop = (totalAngle < 0) || (totalAngle >= Math.PI);
int factor;
if (isOnTop)
factor = 1;
else
factor = -1;
labelLeft = previousLabel.getLeft() + labelWidth * factor + LABEL_MARGIN;
}
dataLabel.setLeft(labelLeft);
dataLabel.setLeftMode(ChartDataLabelLocationMode.ABSOLUTE);
dataLabel.setTop(labelTop);
dataLabel.setTopMode(ChartDataLabelLocationMode.ABSOLUTE);
totalAngle += labelSegmentAngle;
previousLabel = dataLabel;
}
doc.save(getArtifactsDir() + "Charts.DoughnutChartLabelPosition.docx");
getTop() / setTop(double) property value: whether it sets the location of the data label from the top edge of the chart of from the position specified by its getPosition() / setPosition(int) property. The returned value is one of ChartDataLabelLocationMode constants.public void setTopMode(int value)
getTop() / setTop(double) property value: whether it sets the location of the data label from the top edge of the chart of from the position specified by its getPosition() / setPosition(int) property.
Remarks:
The property cannot be set in a Word 2016 chart.
Examples:
Shows how to place data labels of doughnut chart outside doughnut.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final int CHART_WIDTH = 432;
final int CHART_HEIGHT = 252;
Shape shape = builder.insertChart(ChartType.DOUGHNUT, CHART_WIDTH, CHART_HEIGHT);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Hide the legend.
chart.getLegend().setPosition(LegendPosition.NONE);
// Generate data.
final int DATA_LENGTH = 20;
double totalValue = 0.0;
String[] categories = new String[DATA_LENGTH];
double[] values = new double[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++)
{
categories[i] = MessageFormat.format("Category {0}", i);
values[i] = DATA_LENGTH - i;
totalValue += values[i];
}
ChartSeries series = seriesColl.add("Series 1", categories, values);
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.setShowLeaderLines(true);
// The Position property cannot be used for doughnut charts. Let's place data labels using the Left and Top
// properties around a circle outside of the chart doughnut.
// The origin is in the upper left corner of the chart.
final double TITLE_AREA_HEIGHT = 25.5; // This can be calculated using title text and font.
final double DOUGHNUT_CENTER_Y = TITLE_AREA_HEIGHT + (CHART_HEIGHT - TITLE_AREA_HEIGHT) / 2.0;
final double DOUGHNUT_CENTER_X = CHART_WIDTH / 2d;
final double LABEL_HEIGHT = 16.5; // This can be calculated using label font.
final double ONE_CHAR_LABEL_WIDTH = 12.75; // This can be calculated for each label using its text and font.
final double TWO_CHAR_LABEL_WIDTH = 17.25; // This can be calculated for each label using its text and font.
final double Y_MARGIN = 0.75;
final double LABEL_MARGIN = 1.5;
final double LABEL_CIRCLE_RADIUS = CHART_HEIGHT - DOUGHNUT_CENTER_Y - Y_MARGIN - LABEL_HEIGHT / 2.0;
// Because the data points start at the top, the X coordinates used in the Left and Top properties of
// the data labels point to the right and the Y coordinates point down, the starting angle is -PI/2.
double totalAngle = -Math.PI / 2f;
ChartDataLabel previousLabel = null;
for (int i = 0; i < series.getYValues().getCount(); i++)
{
ChartDataLabel dataLabel = dataLabels.get(i);
double value = series.getYValues().get(i).getDoubleValue();
double labelWidth;
if (value < 10)
labelWidth = ONE_CHAR_LABEL_WIDTH;
else
labelWidth = TWO_CHAR_LABEL_WIDTH;
double labelSegmentAngle = value / totalValue * 2.0 * Math.PI;
double labelAngle = labelSegmentAngle / 2.0 + totalAngle;
double labelCenterX = LABEL_CIRCLE_RADIUS * Math.cos(labelAngle) + DOUGHNUT_CENTER_X;
double labelCenterY = LABEL_CIRCLE_RADIUS * Math.sin(labelAngle) + DOUGHNUT_CENTER_Y;
double labelLeft = labelCenterX - labelWidth / 2.0;
double labelTop = labelCenterY - LABEL_HEIGHT / 2.0;
// If the current data label overlaps other labels, move it horizontally.
if ((previousLabel != null) &&
(Math.abs(previousLabel.getTop() - labelTop) < LABEL_HEIGHT) &&
(Math.abs(previousLabel.getLeft() - labelLeft) < labelWidth))
{
// Move right on the top, left on the bottom.
boolean isOnTop = (totalAngle < 0) || (totalAngle >= Math.PI);
int factor;
if (isOnTop)
factor = 1;
else
factor = -1;
labelLeft = previousLabel.getLeft() + labelWidth * factor + LABEL_MARGIN;
}
dataLabel.setLeft(labelLeft);
dataLabel.setLeftMode(ChartDataLabelLocationMode.ABSOLUTE);
dataLabel.setTop(labelTop);
dataLabel.setTopMode(ChartDataLabelLocationMode.ABSOLUTE);
totalAngle += labelSegmentAngle;
previousLabel = dataLabel;
}
doc.save(getArtifactsDir() + "Charts.DoughnutChartLabelPosition.docx");
value - The interpretation mode of the getTop() / setTop(double) property value: whether it sets the location of the data label from the top edge of the chart of from the position specified by its getPosition() / setPosition(int) property. The value must be one of ChartDataLabelLocationMode constants.public int getPosition()
Remarks:
The position can be set for data labels of the following chart series types:
- ChartSeriesType.BAR, ChartSeriesType.COLUMN, ChartSeriesType.HISTOGRAM, ChartSeriesType.PARETO, ChartSeriesType.WATERFALL; allowed values: ChartDataLabelPosition.CENTER, ChartDataLabelPosition.INSIDE_BASE, ChartDataLabelPosition.INSIDE_END and ChartDataLabelPosition.OUTSIDE_END;
- ChartSeriesType.BAR_STACKED, ChartSeriesType.BAR_PERCENT_STACKED, ChartSeriesType.COLUMN_STACKED, ChartSeriesType.COLUMN_PERCENT_STACKED; allowed values: ChartDataLabelPosition.CENTER, ChartDataLabelPosition.INSIDE_BASE and ChartDataLabelPosition.INSIDE_END;
- ChartSeriesType.BUBBLE, ChartSeriesType.BUBBLE_3_D, ChartSeriesType.LINE, ChartSeriesType.LINE_STACKED, ChartSeriesType.LINE_PERCENT_STACKED, ChartSeriesType.SCATTER, ChartSeriesType.STOCK; allowed values: ChartDataLabelPosition.CENTER, ChartDataLabelPosition.LEFT, ChartDataLabelPosition.RIGHT, ChartDataLabelPosition.ABOVE and ChartDataLabelPosition.BELOW;
- ChartSeriesType.PIE, ChartSeriesType.PIE_3_D, ChartSeriesType.PIE_OF_BAR, ChartSeriesType.PIE_OF_PIE; allowed values: ChartDataLabelPosition.CENTER, ChartDataLabelPosition.INSIDE_END, ChartDataLabelPosition.OUTSIDE_END and ChartDataLabelPosition.BEST_FIT;
- ChartSeriesType.BOX_AND_WHISKER; allowed values: ChartDataLabelPosition.LEFT, ChartDataLabelPosition.RIGHT, ChartDataLabelPosition.ABOVE and ChartDataLabelPosition.BELOW.
Examples:
Shows how to set the position of the data label.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert column chart.
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Add series.
ChartSeries series = seriesColl.add(
"Series 1",
new String[] { "Category 1", "Category 2", "Category 3" },
new double[] { 4.0, 5.0, 6.0 });
// Show data labels and set font color.
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.getFont().setColor(Color.WHITE);
// Set data label position.
dataLabels.setPosition(ChartDataLabelPosition.INSIDE_BASE);
dataLabels.get(0).setPosition(ChartDataLabelPosition.OUTSIDE_END);
dataLabels.get(0).getFont().setColor(Color.RED);
doc.save(getArtifactsDir() + "Charts.LabelPosition.docx");
ChartDataLabelPosition constants.public void setPosition(int value)
Remarks:
The position can be set for data labels of the following chart series types:
- ChartSeriesType.BAR, ChartSeriesType.COLUMN, ChartSeriesType.HISTOGRAM, ChartSeriesType.PARETO, ChartSeriesType.WATERFALL; allowed values: ChartDataLabelPosition.CENTER, ChartDataLabelPosition.INSIDE_BASE, ChartDataLabelPosition.INSIDE_END and ChartDataLabelPosition.OUTSIDE_END;
- ChartSeriesType.BAR_STACKED, ChartSeriesType.BAR_PERCENT_STACKED, ChartSeriesType.COLUMN_STACKED, ChartSeriesType.COLUMN_PERCENT_STACKED; allowed values: ChartDataLabelPosition.CENTER, ChartDataLabelPosition.INSIDE_BASE and ChartDataLabelPosition.INSIDE_END;
- ChartSeriesType.BUBBLE, ChartSeriesType.BUBBLE_3_D, ChartSeriesType.LINE, ChartSeriesType.LINE_STACKED, ChartSeriesType.LINE_PERCENT_STACKED, ChartSeriesType.SCATTER, ChartSeriesType.STOCK; allowed values: ChartDataLabelPosition.CENTER, ChartDataLabelPosition.LEFT, ChartDataLabelPosition.RIGHT, ChartDataLabelPosition.ABOVE and ChartDataLabelPosition.BELOW;
- ChartSeriesType.PIE, ChartSeriesType.PIE_3_D, ChartSeriesType.PIE_OF_BAR, ChartSeriesType.PIE_OF_PIE; allowed values: ChartDataLabelPosition.CENTER, ChartDataLabelPosition.INSIDE_END, ChartDataLabelPosition.OUTSIDE_END and ChartDataLabelPosition.BEST_FIT;
- ChartSeriesType.BOX_AND_WHISKER; allowed values: ChartDataLabelPosition.LEFT, ChartDataLabelPosition.RIGHT, ChartDataLabelPosition.ABOVE and ChartDataLabelPosition.BELOW.
Examples:
Shows how to set the position of the data label.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert column chart.
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Add series.
ChartSeries series = seriesColl.add(
"Series 1",
new String[] { "Category 1", "Category 2", "Category 3" },
new double[] { 4.0, 5.0, 6.0 });
// Show data labels and set font color.
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.getFont().setColor(Color.WHITE);
// Set data label position.
dataLabels.setPosition(ChartDataLabelPosition.INSIDE_BASE);
dataLabels.get(0).setPosition(ChartDataLabelPosition.OUTSIDE_END);
dataLabels.get(0).getFont().setColor(Color.RED);
doc.save(getArtifactsDir() + "Charts.LabelPosition.docx");
value - The position of the data label. The value must be one of ChartDataLabelPosition constants.public boolean isInherited()
public java.lang.String generateItemText()
public java.lang.Object fetchSpecialDefaultRunPropertyValue(int key)
public java.lang.Object getRelativePropertyValue(int key,
java.lang.Object value)
protected java.lang.Object memberwiseClone()