public class ChartSeries extends java.lang.Object implements IChartDataPoint, java.lang.Cloneable
To learn more, visit the Working with Charts documentation article.
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 |
add(ChartXValue xValue)
Adds the specified X value to the chart series.
|
void |
add(ChartXValue xValue,
ChartYValue yValue)
Adds the specified X and Y values to the chart series.
|
void |
add(ChartXValue xValue,
ChartYValue yValue,
double bubbleSize)
Adds the specified X value, Y value and bubble size to the chart series.
|
void |
clear()
Removes all data values from the chart series.
|
void |
clearValues()
Removes all data values from the chart series with preserving the format of the data points and data labels.
|
void |
copyFormatFrom(int dataPointIndex)
Copies default data point format from the data point with the specified index.
|
boolean |
getBubble3D()
Specifies whether the bubbles in Bubble chart should have a 3-D effect applied to them.
|
BubbleSizeCollection |
getBubbleSizes()
Gets a collection of bubble sizes for this chart series.
|
ChartDataLabelCollection |
getDataLabels()
Specifies the settings for the data labels for the entire series.
|
ChartDataPointCollection |
getDataPoints()
Returns a collection of formatting objects for all data points in this series.
|
int |
getExplosion()
Specifies the amount the data point shall be moved from the center of the pie.
|
ChartFormat |
getFormat()
Provides access to fill and line formatting of the series.
|
boolean |
getInvertIfNegative()
Specifies whether the parent element shall inverts its colors if the value is negative.
|
ChartLegendEntry |
getLegendEntry()
Gets a legend entry for this chart series.
|
ChartMarker |
getMarker()
Specifies a data marker.
|
java.lang.String |
getName()
Gets the name of the series, if name is not set explicitly it is generated using index.
|
int |
getSeriesType()
Gets the type of this chart series.
|
boolean |
getSmooth()
Allows to specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines.
|
ChartXValueCollection |
getXValues()
Gets a collection of X values for this chart series.
|
ChartYValueCollection |
getYValues()
Gets a collection of Y values for this chart series.
|
boolean |
hasDataLabels()
Gets a flag indicating whether data labels are displayed for the series.
|
void |
hasDataLabels(boolean value)
Sets a flag indicating whether data labels are displayed for the series.
|
void |
insert(int index,
ChartXValue xValue)
Inserts the specified X value into the chart series at the specified index.
|
void |
insert(int index,
ChartXValue xValue,
ChartYValue yValue)
Inserts the specified X and Y values into the chart series at the specified index.
|
void |
insert(int index,
ChartXValue xValue,
ChartYValue yValue,
double bubbleSize)
Inserts the specified X value, Y value and bubble size into the chart series at the specified index.
|
protected java.lang.Object |
memberwiseClone() |
void |
remove(int index)
Removes the X value, Y value, and bubble size, if supported, from the chart series at the specified index.
|
void |
setBubble3D(boolean value)
Specifies whether the bubbles in Bubble chart should have a 3-D effect applied to them.
|
void |
setExplosion(int value)
Specifies the amount the data point shall be moved from the center of the pie.
|
void |
setInvertIfNegative(boolean value)
Specifies whether the parent element shall inverts its colors if the value is negative.
|
void |
setName(java.lang.String value)
Sets the name of the series, if name is not set explicitly it is generated using index.
|
void |
setSmooth(boolean value)
Allows to specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines.
|
public void add(ChartXValue xValue)
Examples:
Shows how to populate chart series with data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series1 = chart.getSeries().get(0);
// Clear X and Y values of the first series.
series1.clearValues();
// Populate the series with data.
series1.add(ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0), 10.0);
series1.add(ChartXValue.fromDouble(5.0), ChartYValue.fromDouble(5.0));
series1.add(ChartXValue.fromDouble(7.0), ChartYValue.fromDouble(11.0));
series1.add(ChartXValue.fromDouble(9.0));
ChartSeries series2 = chart.getSeries().get(1);
// Clear X and Y values of the second series.
series2.clear();
// Populate the series with data.
series2.add(ChartXValue.fromDouble(2.0), ChartYValue.fromDouble(4.0));
series2.add(ChartXValue.fromDouble(4.0), ChartYValue.fromDouble(7.0));
series2.add(ChartXValue.fromDouble(6.0), ChartYValue.fromDouble(14.0));
series2.add(ChartXValue.fromDouble(8.0), ChartYValue.fromDouble(7.0));
doc.save(getArtifactsDir() + "Charts.PopulateChartWithData.docx");
public void add(ChartXValue xValue, ChartYValue yValue)
Examples:
Shows how to add/remove chart data values.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder();
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries department1Series = chart.getSeries().get(0);
ChartSeries department2Series = chart.getSeries().get(1);
// Remove the first value in the both series.
department1Series.remove(0);
department2Series.remove(0);
// Add new values to the both series.
ChartXValue newXCategory = ChartXValue.fromString("Q1, 2023");
department1Series.add(newXCategory, ChartYValue.fromDouble(10.3));
department2Series.add(newXCategory, ChartYValue.fromDouble(5.7));
doc.save(getArtifactsDir() + "Charts.ChartDataValues.docx");
Shows how to populate chart series with data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series1 = chart.getSeries().get(0);
// Clear X and Y values of the first series.
series1.clearValues();
// Populate the series with data.
series1.add(ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0), 10.0);
series1.add(ChartXValue.fromDouble(5.0), ChartYValue.fromDouble(5.0));
series1.add(ChartXValue.fromDouble(7.0), ChartYValue.fromDouble(11.0));
series1.add(ChartXValue.fromDouble(9.0));
ChartSeries series2 = chart.getSeries().get(1);
// Clear X and Y values of the second series.
series2.clear();
// Populate the series with data.
series2.add(ChartXValue.fromDouble(2.0), ChartYValue.fromDouble(4.0));
series2.add(ChartXValue.fromDouble(4.0), ChartYValue.fromDouble(7.0));
series2.add(ChartXValue.fromDouble(6.0), ChartYValue.fromDouble(14.0));
series2.add(ChartXValue.fromDouble(8.0), ChartYValue.fromDouble(7.0));
doc.save(getArtifactsDir() + "Charts.PopulateChartWithData.docx");
public void add(ChartXValue xValue, ChartYValue yValue, double bubbleSize)
Examples:
Shows how to populate chart series with data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series1 = chart.getSeries().get(0);
// Clear X and Y values of the first series.
series1.clearValues();
// Populate the series with data.
series1.add(ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0), 10.0);
series1.add(ChartXValue.fromDouble(5.0), ChartYValue.fromDouble(5.0));
series1.add(ChartXValue.fromDouble(7.0), ChartYValue.fromDouble(11.0));
series1.add(ChartXValue.fromDouble(9.0));
ChartSeries series2 = chart.getSeries().get(1);
// Clear X and Y values of the second series.
series2.clear();
// Populate the series with data.
series2.add(ChartXValue.fromDouble(2.0), ChartYValue.fromDouble(4.0));
series2.add(ChartXValue.fromDouble(4.0), ChartYValue.fromDouble(7.0));
series2.add(ChartXValue.fromDouble(6.0), ChartYValue.fromDouble(14.0));
series2.add(ChartXValue.fromDouble(8.0), ChartYValue.fromDouble(7.0));
doc.save(getArtifactsDir() + "Charts.PopulateChartWithData.docx");
public void insert(int index,
ChartXValue xValue)
Remarks:
The corresponding data point with default formatting will be inserted into the data point collection. And, if data labels are displayed, the corresponding data label with default formatting will be inserted too.
Examples:
Shows how to insert data into a chart series.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series1 = chart.getSeries().get(0);
// Clear X and Y values of the first series.
series1.clearValues();
// Populate the series with data.
series1.insert(0, ChartXValue.fromDouble(3.0));
series1.insert(1, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0));
series1.insert(2, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0));
series1.insert(3, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0), 10.0);
doc.save(getArtifactsDir() + "Charts.PopulateChartWithData.docx");
public void insert(int index,
ChartXValue xValue,
ChartYValue yValue)
Remarks:
The corresponding data point with default formatting will be inserted into the data point collection. And, if data labels are displayed, the corresponding data label with default formatting will be inserted too.
Examples:
Shows how to insert data into a chart series.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series1 = chart.getSeries().get(0);
// Clear X and Y values of the first series.
series1.clearValues();
// Populate the series with data.
series1.insert(0, ChartXValue.fromDouble(3.0));
series1.insert(1, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0));
series1.insert(2, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0));
series1.insert(3, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0), 10.0);
doc.save(getArtifactsDir() + "Charts.PopulateChartWithData.docx");
public void insert(int index,
ChartXValue xValue,
ChartYValue yValue,
double bubbleSize)
Remarks:
The corresponding data point with default formatting will be inserted into the data point collection. And, if data labels are displayed, the corresponding data label with default formatting will be inserted too.
Examples:
Shows how to insert data into a chart series.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series1 = chart.getSeries().get(0);
// Clear X and Y values of the first series.
series1.clearValues();
// Populate the series with data.
series1.insert(0, ChartXValue.fromDouble(3.0));
series1.insert(1, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0));
series1.insert(2, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0));
series1.insert(3, ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0), 10.0);
doc.save(getArtifactsDir() + "Charts.PopulateChartWithData.docx");
public void remove(int index)
Examples:
Shows how to add/remove chart data values.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder();
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries department1Series = chart.getSeries().get(0);
ChartSeries department2Series = chart.getSeries().get(1);
// Remove the first value in the both series.
department1Series.remove(0);
department2Series.remove(0);
// Add new values to the both series.
ChartXValue newXCategory = ChartXValue.fromString("Q1, 2023");
department1Series.add(newXCategory, ChartYValue.fromDouble(10.3));
department2Series.add(newXCategory, ChartYValue.fromDouble(5.7));
doc.save(getArtifactsDir() + "Charts.ChartDataValues.docx");
public void clear()
Examples:
Shows how to populate chart series with data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series1 = chart.getSeries().get(0);
// Clear X and Y values of the first series.
series1.clearValues();
// Populate the series with data.
series1.add(ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0), 10.0);
series1.add(ChartXValue.fromDouble(5.0), ChartYValue.fromDouble(5.0));
series1.add(ChartXValue.fromDouble(7.0), ChartYValue.fromDouble(11.0));
series1.add(ChartXValue.fromDouble(9.0));
ChartSeries series2 = chart.getSeries().get(1);
// Clear X and Y values of the second series.
series2.clear();
// Populate the series with data.
series2.add(ChartXValue.fromDouble(2.0), ChartYValue.fromDouble(4.0));
series2.add(ChartXValue.fromDouble(4.0), ChartYValue.fromDouble(7.0));
series2.add(ChartXValue.fromDouble(6.0), ChartYValue.fromDouble(14.0));
series2.add(ChartXValue.fromDouble(8.0), ChartYValue.fromDouble(7.0));
doc.save(getArtifactsDir() + "Charts.PopulateChartWithData.docx");
public void clearValues()
Examples:
Shows how to populate chart series with data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeries series1 = chart.getSeries().get(0);
// Clear X and Y values of the first series.
series1.clearValues();
// Populate the series with data.
series1.add(ChartXValue.fromDouble(3.0), ChartYValue.fromDouble(10.0), 10.0);
series1.add(ChartXValue.fromDouble(5.0), ChartYValue.fromDouble(5.0));
series1.add(ChartXValue.fromDouble(7.0), ChartYValue.fromDouble(11.0));
series1.add(ChartXValue.fromDouble(9.0));
ChartSeries series2 = chart.getSeries().get(1);
// Clear X and Y values of the second series.
series2.clear();
// Populate the series with data.
series2.add(ChartXValue.fromDouble(2.0), ChartYValue.fromDouble(4.0));
series2.add(ChartXValue.fromDouble(4.0), ChartYValue.fromDouble(7.0));
series2.add(ChartXValue.fromDouble(6.0), ChartYValue.fromDouble(14.0));
series2.add(ChartXValue.fromDouble(8.0), ChartYValue.fromDouble(7.0));
doc.save(getArtifactsDir() + "Charts.PopulateChartWithData.docx");
public void copyFormatFrom(int dataPointIndex)
Examples:
Shows how to copy data point format.
Document doc = new Document(getMyDir() + "DataPoint format.docx");
// Get the chart and series to update format.
Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
ChartSeries series = shape.getChart().getSeries().get(0);
ChartDataPointCollection dataPoints = series.getDataPoints();
Assert.assertTrue(dataPoints.hasDefaultFormat(0));
Assert.assertFalse(dataPoints.hasDefaultFormat(1));
// Copy format of the data point with index 1 to the data point with index 2
// so that the data point 2 looks the same as the data point 1.
dataPoints.copyFormat(0, 1);
Assert.assertTrue(dataPoints.hasDefaultFormat(0));
Assert.assertTrue(dataPoints.hasDefaultFormat(1));
// Copy format of the data point with index 0 to the series defaults so that all data points
// in the series that have the default format look the same as the data point 0.
series.copyFormatFrom(1);
Assert.assertTrue(dataPoints.hasDefaultFormat(0));
Assert.assertTrue(dataPoints.hasDefaultFormat(1));
doc.save(getArtifactsDir() + "Charts.CopyDataPointFormat.docx");
public int getExplosion()
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());
}
}
getExplosion in interface IChartDataPointint value.public void setExplosion(int 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());
}
}
setExplosion in interface IChartDataPointvalue - The corresponding int value.public boolean getInvertIfNegative()
Examples:
Shows how to work with data points on a line chart.
public void chartDataPoint() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 500.0, 350.0);
Chart chart = shape.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());
// Emphasize the chart's data points by making them appear as diamond shapes.
for (ChartSeries series : chart.getSeries())
applyDataPoints(series, 4, MarkerSymbol.DIAMOND, 15);
// Smooth out the line that represents the first data series.
chart.getSeries().get(0).setSmooth(true);
// Verify that data points for the first series will not invert their colors if the value is negative.
Iterator<ChartDataPoint> enumerator = chart.getSeries().get(0).getDataPoints().iterator();
while (enumerator.hasNext()) {
Assert.assertFalse(enumerator.next().getInvertIfNegative());
}
ChartDataPoint dataPoint = chart.getSeries().get(1).getDataPoints().get(2);
dataPoint.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can clear format individually.
dataPoint.clearFormat();
// We can also strip an entire series of data points at once.
chart.getSeries().get(2).getDataPoints().clearFormat();
doc.save(getArtifactsDir() + "Charts.ChartDataPoint.docx");
}
/// <summary>
/// Applies a number of data points to a series.
/// </summary>
private static void applyDataPoints(ChartSeries series, int dataPointsCount, int markerSymbol, int dataPointSize) {
for (int i = 0; i < dataPointsCount; i++) {
ChartDataPoint point = series.getDataPoints().get(i);
point.getMarker().setSymbol(markerSymbol);
point.getMarker().setSize(dataPointSize);
Assert.assertEquals(point.getIndex(), i);
}
}
getInvertIfNegative in interface IChartDataPointboolean value.public void setInvertIfNegative(boolean value)
Examples:
Shows how to work with data points on a line chart.
public void chartDataPoint() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 500.0, 350.0);
Chart chart = shape.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());
// Emphasize the chart's data points by making them appear as diamond shapes.
for (ChartSeries series : chart.getSeries())
applyDataPoints(series, 4, MarkerSymbol.DIAMOND, 15);
// Smooth out the line that represents the first data series.
chart.getSeries().get(0).setSmooth(true);
// Verify that data points for the first series will not invert their colors if the value is negative.
Iterator<ChartDataPoint> enumerator = chart.getSeries().get(0).getDataPoints().iterator();
while (enumerator.hasNext()) {
Assert.assertFalse(enumerator.next().getInvertIfNegative());
}
ChartDataPoint dataPoint = chart.getSeries().get(1).getDataPoints().get(2);
dataPoint.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can clear format individually.
dataPoint.clearFormat();
// We can also strip an entire series of data points at once.
chart.getSeries().get(2).getDataPoints().clearFormat();
doc.save(getArtifactsDir() + "Charts.ChartDataPoint.docx");
}
/// <summary>
/// Applies a number of data points to a series.
/// </summary>
private static void applyDataPoints(ChartSeries series, int dataPointsCount, int markerSymbol, int dataPointSize) {
for (int i = 0; i < dataPointsCount; i++) {
ChartDataPoint point = series.getDataPoints().get(i);
point.getMarker().setSymbol(markerSymbol);
point.getMarker().setSize(dataPointSize);
Assert.assertEquals(point.getIndex(), i);
}
}
setInvertIfNegative in interface IChartDataPointvalue - The corresponding boolean value.public ChartMarker getMarker()
Examples:
Show how to set marker formatting.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.SCATTER, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add("AW Series 1", new double[] { 0.7, 1.8, 2.6, 3.9 },
new double[] { 2.7, 3.2, 0.8, 1.7 });
// Set marker formatting.
series.getMarker().setSize(40);
series.getMarker().setSymbol(MarkerSymbol.SQUARE);
ChartDataPointCollection dataPoints = series.getDataPoints();
dataPoints.get(0).getMarker().getFormat().getFill().presetTextured(PresetTexture.DENIM);
dataPoints.get(0).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(0).getMarker().getFormat().getStroke().setBackColor(Color.RED);
dataPoints.get(1).getMarker().getFormat().getFill().presetTextured(PresetTexture.WATER_DROPLETS);
dataPoints.get(1).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(1).getMarker().getFormat().getStroke().setVisible(false);
dataPoints.get(2).getMarker().getFormat().getFill().presetTextured(PresetTexture.GREEN_MARBLE);
dataPoints.get(2).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(3).getMarker().getFormat().getFill().presetTextured(PresetTexture.OAK);
dataPoints.get(3).getMarker().getFormat().getStroke().setForeColor(Color.YELLOW);
dataPoints.get(3).getMarker().getFormat().getStroke().setTransparency(0.5);
doc.save(getArtifactsDir() + "Charts.MarkerFormatting.docx");
getMarker in interface IChartDataPointChartMarker value.public boolean getBubble3D()
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");
getBubble3D in interface IChartDataPointboolean value.public void setBubble3D(boolean value)
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");
setBubble3D in interface IChartDataPointvalue - The corresponding boolean value.public ChartDataPointCollection getDataPoints()
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 java.lang.String getName()
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 setName(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 - The name of the series, if name is not set explicitly it is generated using index.public boolean getSmooth()
Examples:
Shows how to work with data points on a line chart.
public void chartDataPoint() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 500.0, 350.0);
Chart chart = shape.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());
// Emphasize the chart's data points by making them appear as diamond shapes.
for (ChartSeries series : chart.getSeries())
applyDataPoints(series, 4, MarkerSymbol.DIAMOND, 15);
// Smooth out the line that represents the first data series.
chart.getSeries().get(0).setSmooth(true);
// Verify that data points for the first series will not invert their colors if the value is negative.
Iterator<ChartDataPoint> enumerator = chart.getSeries().get(0).getDataPoints().iterator();
while (enumerator.hasNext()) {
Assert.assertFalse(enumerator.next().getInvertIfNegative());
}
ChartDataPoint dataPoint = chart.getSeries().get(1).getDataPoints().get(2);
dataPoint.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can clear format individually.
dataPoint.clearFormat();
// We can also strip an entire series of data points at once.
chart.getSeries().get(2).getDataPoints().clearFormat();
doc.save(getArtifactsDir() + "Charts.ChartDataPoint.docx");
}
/// <summary>
/// Applies a number of data points to a series.
/// </summary>
private static void applyDataPoints(ChartSeries series, int dataPointsCount, int markerSymbol, int dataPointSize) {
for (int i = 0; i < dataPointsCount; i++) {
ChartDataPoint point = series.getDataPoints().get(i);
point.getMarker().setSymbol(markerSymbol);
point.getMarker().setSize(dataPointSize);
Assert.assertEquals(point.getIndex(), i);
}
}
boolean value.public void setSmooth(boolean value)
Examples:
Shows how to work with data points on a line chart.
public void chartDataPoint() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.LINE, 500.0, 350.0);
Chart chart = shape.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());
// Emphasize the chart's data points by making them appear as diamond shapes.
for (ChartSeries series : chart.getSeries())
applyDataPoints(series, 4, MarkerSymbol.DIAMOND, 15);
// Smooth out the line that represents the first data series.
chart.getSeries().get(0).setSmooth(true);
// Verify that data points for the first series will not invert their colors if the value is negative.
Iterator<ChartDataPoint> enumerator = chart.getSeries().get(0).getDataPoints().iterator();
while (enumerator.hasNext()) {
Assert.assertFalse(enumerator.next().getInvertIfNegative());
}
ChartDataPoint dataPoint = chart.getSeries().get(1).getDataPoints().get(2);
dataPoint.getFormat().getFill().setColor(Color.RED);
// For a cleaner looking graph, we can clear format individually.
dataPoint.clearFormat();
// We can also strip an entire series of data points at once.
chart.getSeries().get(2).getDataPoints().clearFormat();
doc.save(getArtifactsDir() + "Charts.ChartDataPoint.docx");
}
/// <summary>
/// Applies a number of data points to a series.
/// </summary>
private static void applyDataPoints(ChartSeries series, int dataPointsCount, int markerSymbol, int dataPointSize) {
for (int i = 0; i < dataPointsCount; i++) {
ChartDataPoint point = series.getDataPoints().get(i);
point.getMarker().setSymbol(markerSymbol);
point.getMarker().setSize(dataPointSize);
Assert.assertEquals(point.getIndex(), i);
}
}
value - The corresponding boolean value.public boolean hasDataLabels()
Examples:
Shows how to enable and configure data labels for a chart series.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a line chart, then clear its demo data series to start with a clean chart,
// and then set a title.
Shape shape = builder.insertChart(ChartType.LINE, 500.0, 300.0);
Chart chart = shape.getChart();
chart.getSeries().clear();
chart.getTitle().setText("Monthly sales report");
// Insert a custom chart series with months as categories for the X-axis,
// and respective decimal amounts for the Y-axis.
ChartSeries series = chart.getSeries().add("Revenue",
new String[]{"January", "February", "March"},
new double[]{25.611d, 21.439d, 33.750d});
// Enable data labels, and then apply a custom number format for values displayed in the data labels.
// This format will treat displayed decimal values as millions of US Dollars.
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.getNumberFormat().setFormatCode("\"US$\" #,##0.000\"M\"");
dataLabels.getFont().setSize(12.0);
doc.save(getArtifactsDir() + "Charts.DataLabelNumberFormat.docx");
public void hasDataLabels(boolean value)
Examples:
Shows how to enable and configure data labels for a chart series.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a line chart, then clear its demo data series to start with a clean chart,
// and then set a title.
Shape shape = builder.insertChart(ChartType.LINE, 500.0, 300.0);
Chart chart = shape.getChart();
chart.getSeries().clear();
chart.getTitle().setText("Monthly sales report");
// Insert a custom chart series with months as categories for the X-axis,
// and respective decimal amounts for the Y-axis.
ChartSeries series = chart.getSeries().add("Revenue",
new String[]{"January", "February", "March"},
new double[]{25.611d, 21.439d, 33.750d});
// Enable data labels, and then apply a custom number format for values displayed in the data labels.
// This format will treat displayed decimal values as millions of US Dollars.
series.hasDataLabels(true);
ChartDataLabelCollection dataLabels = series.getDataLabels();
dataLabels.setShowValue(true);
dataLabels.getNumberFormat().setFormatCode("\"US$\" #,##0.000\"M\"");
dataLabels.getFont().setSize(12.0);
doc.save(getArtifactsDir() + "Charts.DataLabelNumberFormat.docx");
value - A flag indicating whether data labels are displayed for the series.public ChartDataLabelCollection getDataLabels()
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());
}
}
ChartDataLabelCollection value.public ChartFormat getFormat()
Examples:
Sows how to set series color.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
ChartSeriesCollection seriesColl = chart.getSeries();
// Delete default generated series.
seriesColl.clear();
// Create category names array.
String[] categories = new String[] { "Category 1", "Category 2" };
// Adding new series. Value and category arrays must be the same size.
ChartSeries series1 = seriesColl.add("Series 1", categories, new double[] { 1.0, 2.0 });
ChartSeries series2 = seriesColl.add("Series 2", categories, new double[] { 3.0, 4.0 });
ChartSeries series3 = seriesColl.add("Series 3", categories, new double[] { 5.0, 6.0 });
// Set series color.
series1.getFormat().getFill().setForeColor(Color.RED);
series2.getFormat().getFill().setForeColor(Color.YELLOW);
series3.getFormat().getFill().setForeColor(Color.BLUE);
doc.save(getArtifactsDir() + "Charts.SeriesColor.docx");
ChartFormat value.public ChartLegendEntry getLegendEntry()
Examples:
Shows how to work with a legend font.
Document doc = new Document(getMyDir() + "Reporting engine template - Chart series (Java).docx");
Chart chart = ((Shape)doc.getChild(NodeType.SHAPE, 0, true)).getChart();
ChartLegend chartLegend = chart.getLegend();
// Set default font size all legend entries.
chartLegend.getFont().setSize(14.0);
// Change font for specific legend entry.
chartLegend.getLegendEntries().get(1).getFont().setItalic(true);
chartLegend.getLegendEntries().get(1).getFont().setSize(12.0);
// Get legend entry for chart series.
ChartLegendEntry legendEntry = chart.getSeries().get(0).getLegendEntry();
doc.save(getArtifactsDir() + "Charts.LegendFont.docx");
public int getSeriesType()
Examples:
Shows how to remove specific chart serie.
Document doc = new Document(getMyDir() + "Reporting engine template - Chart series (Java).docx");
Chart chart = ((Shape)doc.getChild(NodeType.SHAPE, 0, true)).getChart();
// Remove all series of the Column type.
for (int i = chart.getSeries().getCount() - 1; i >= 0; i--)
{
if (chart.getSeries().get(i).getSeriesType() == ChartSeriesType.COLUMN)
chart.getSeries().removeAt(i);
}
chart.getSeries().add(
"Aspose Series",
new String[] { "Category 1", "Category 2", "Category 3", "Category 4" },
new double[] { 5.6, 7.1, 2.9, 8.9 });
doc.save(getArtifactsDir() + "Charts.RemoveSpecificChartSeries.docx");
ChartSeriesType constants.public ChartXValueCollection getXValues()
Examples:
Shows how to work with the format code of the chart data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a Bubble chart.
Shape shape = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add(
"Series1",
new double[] { 1.0, 1.9, 2.45, 3.0 },
new double[] { 1.0, -0.9, 1.82, 0.0 },
new double[] { 2.0, 1.1, 2.95, 2.0 });
// Show data labels.
series.hasDataLabels(true);
series.getDataLabels().setShowCategoryName(true);
series.getDataLabels().setShowValue(true);
series.getDataLabels().setShowBubbleSize(true);
// Set data format codes.
series.getXValues().setFormatCode("#,##0.0#");
series.getYValues().setFormatCode("#,##0.0#;[Red]\\-#,##0.0#");
series.getBubbleSizes().setFormatCode("#,##0.0#");
doc.save(getArtifactsDir() + "Charts.FormatCode.docx");
public ChartYValueCollection getYValues()
Examples:
Shows how to work with the format code of the chart data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a Bubble chart.
Shape shape = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add(
"Series1",
new double[] { 1.0, 1.9, 2.45, 3.0 },
new double[] { 1.0, -0.9, 1.82, 0.0 },
new double[] { 2.0, 1.1, 2.95, 2.0 });
// Show data labels.
series.hasDataLabels(true);
series.getDataLabels().setShowCategoryName(true);
series.getDataLabels().setShowValue(true);
series.getDataLabels().setShowBubbleSize(true);
// Set data format codes.
series.getXValues().setFormatCode("#,##0.0#");
series.getYValues().setFormatCode("#,##0.0#;[Red]\\-#,##0.0#");
series.getBubbleSizes().setFormatCode("#,##0.0#");
doc.save(getArtifactsDir() + "Charts.FormatCode.docx");
public BubbleSizeCollection getBubbleSizes()
Examples:
Shows how to work with the format code of the chart data.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a Bubble chart.
Shape shape = builder.insertChart(ChartType.BUBBLE, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add(
"Series1",
new double[] { 1.0, 1.9, 2.45, 3.0 },
new double[] { 1.0, -0.9, 1.82, 0.0 },
new double[] { 2.0, 1.1, 2.95, 2.0 });
// Show data labels.
series.hasDataLabels(true);
series.getDataLabels().setShowCategoryName(true);
series.getDataLabels().setShowValue(true);
series.getDataLabels().setShowBubbleSize(true);
// Set data format codes.
series.getXValues().setFormatCode("#,##0.0#");
series.getYValues().setFormatCode("#,##0.0#;[Red]\\-#,##0.0#");
series.getBubbleSizes().setFormatCode("#,##0.0#");
doc.save(getArtifactsDir() + "Charts.FormatCode.docx");
protected java.lang.Object memberwiseClone()