ChartDataPoint
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.words.IChartDataPoint, java.lang.Cloneable
public class ChartDataPoint implements IChartDataPoint, Cloneable
Allows to specify formatting of a single data point on the chart.
To learn more, visit the Working with Charts documentation article.
Remarks:
On a series, the ChartDataPoint object is a member of the ChartDataPointCollection. The ChartDataPointCollection contains a ChartDataPoint object for each point.
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 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");
}
///
/// Applies a number of data points to a series.
///
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);
}
}
Methods
| Method | Description |
|---|---|
| clearFormat() | Clears format of this data point. |
| getBubble3D() | Specifies whether the bubbles in Bubble chart should have a 3-D effect applied to them. |
| getExplosion() | Specifies the amount the data point shall be moved from the center of the pie. |
| getFormat() | Provides access to fill and line formatting of this data point. |
| getIndex() | Index of the data point this object applies formatting to. |
| getInvertIfNegative() | Specifies whether the parent element shall inverts its colors if the value is negative. |
| getMarker() | Specifies chart data marker. |
| getShapeType() | |
| isFillSupported() | |
| isFormatDefined() | |
| isTotal() | Gets a flag indicating whether the data point is a total. |
| materializeSpPr() | |
| setBubble3D(boolean value) | Specifies whether the bubbles in Bubble chart should have a 3-D effect applied to them. |
| setExplosion(int value) | Specifies the amount the data point shall be moved from the center of the pie. |
| setInvertIfNegative(boolean value) | Specifies whether the parent element shall inverts its colors if the value is negative. |
| setShapeType(int value) |
clearFormat()
public void clearFormat()
Clears format of this data point. The properties are set to the default values defined in the parent series.
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 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");
}
///
/// Applies a number of data points to a series.
///
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);
}
}
getBubble3D()
public boolean getBubble3D()
Specifies whether the bubbles in Bubble chart should have a 3-D effect applied to them.
Returns: boolean - The corresponding boolean value.
getExplosion()
public int getExplosion()
Specifies the amount the data point shall be moved from the center of the pie. Can be negative, negative means that property is not set and no explosion should be applied. Applies only to Pie charts.
Examples:
Shows how to move the slices of a pie chart away from the center.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.PIE, 500.0, 350.0);
Chart chart = shape.getChart();
Assert.assertEquals(1, chart.getSeries().getCount());
Assert.assertEquals("Sales", chart.getSeries().get(0).getName());
// "Slices" of a pie chart may be moved away from the center by a distance via the respective data point's Explosion attribute.
// Add a data point to the first portion of the pie chart and move it away from the center by 10 points.
// Aspose.Words create data points automatically if them does not exist.
ChartDataPoint dataPoint = chart.getSeries().get(0).getDataPoints().get(0);
dataPoint.setExplosion(10);
// Displace the second portion by a greater distance.
dataPoint = chart.getSeries().get(0).getDataPoints().get(1);
dataPoint.setExplosion(40);
doc.save(getArtifactsDir() + "Charts.PieChartExplosion.docx");
Returns: int - The corresponding int value.
getFormat()
public ChartFormat getFormat()
Provides access to fill and line formatting of this data point.
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 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");
}
///
/// Applies a number of data points to a series.
///
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);
}
}
Shows how to set individual formatting for categories of a column chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.COLUMN, 432.0, 252.0);
Chart chart = shape.getChart();
// Delete default generated series.
chart.getSeries().clear();
// Adding new series.
ChartSeries series = chart.getSeries().add("Series 1",
new String[] { "Category 1", "Category 2", "Category 3", "Category 4" },
new double[] { 1.0, 2.0, 3.0, 4.0 });
// Set column formatting.
ChartDataPointCollection dataPoints = series.getDataPoints();
dataPoints.get(0).getFormat().getFill().presetTextured(PresetTexture.DENIM);
dataPoints.get(1).getFormat().getFill().setForeColor(Color.RED);
dataPoints.get(2).getFormat().getFill().setForeColor(Color.YELLOW);
dataPoints.get(3).getFormat().getFill().setForeColor(Color.BLUE);
doc.save(getArtifactsDir() + "Charts.DataPointsFormatting.docx");
Returns: ChartFormat - The corresponding ChartFormat value.
getIndex()
public int getIndex()
Index of the data point this object applies formatting to.
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 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");
}
///
/// Applies a number of data points to a series.
///
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);
}
}
Returns: int - The corresponding int value.
getInvertIfNegative()
public boolean getInvertIfNegative()
Specifies whether the parent element shall inverts its colors if the value is negative.
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 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");
}
///
/// Applies a number of data points to a series.
///
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);
}
}
Returns: boolean - The corresponding boolean value.
getMarker()
public ChartMarker getMarker()
Specifies chart data marker.
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");
Returns: ChartMarker - The corresponding ChartMarker value.
getShapeType()
public int getShapeType()
Returns: int
isFillSupported()
public boolean isFillSupported()
Returns: boolean
isFormatDefined()
public boolean isFormatDefined()
Returns: boolean
isTotal()
public boolean isTotal()
Gets a flag indicating whether the data point is a total. Applies only to Waterfall charts.
Remarks:
In a waterfall chart, total columns represent intermediate or final totals. If this property returns true, the data point is such a total column.
Examples:
Shows how to determine whether a data point is a total in a waterfall chart.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a Waterfall chart.
Shape shape = builder.insertChart(ChartType.WATERFALL, 450.0, 450.0);
Chart chart = shape.getChart();
chart.getTitle().setText("New Zealand GDP");
// Delete default generated series.
chart.getSeries().clear();
// Add a series where the start value, the subtotal and the final value are totals.
ChartSeries series = chart.getSeries().add(
"New Zealand GDP",
new String[] { "2018", "2019 growth", "2020 growth", "2020", "2021 growth", "2022 growth", "2022" },
new double[] { 100.0, 0.57, -0.25, 100.32, 20.22, -2.92, 117.62 },
new boolean[] { true, false, false, true, false, false, true });
// Print the type of each data point.
for (int i = 0; i < series.getYValues().getCount(); i++)
{
if (series.isTotal(i))
System.out.println("Data point {i} is Subtotal");
else if (series.getYValues().get(i).getDoubleValue() > 0)
System.out.println("Data point {i} is Increase");
else
System.out.println("Data point {i} is Decrease");
}
// The same flag is available on the data point itself.
System.out.println("Data point 3 is total: {series.DataPoints[3].IsTotal}");
doc.save(getArtifactsDir() + "Charts.ChartSeriesAndDataPointIsTotal.docx");
Returns: boolean - A flag indicating whether the data point is a total.
materializeSpPr()
public void materializeSpPr()
setBubble3D(boolean value)
public void setBubble3D(boolean value)
Specifies whether the bubbles in Bubble chart should have a 3-D effect applied to them.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean | The corresponding boolean value. |
setExplosion(int value)
public void setExplosion(int value)
Specifies the amount the data point shall be moved from the center of the pie. Can be negative, negative means that property is not set and no explosion should be applied. Applies only to Pie charts.
Examples:
Shows how to move the slices of a pie chart away from the center.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertChart(ChartType.PIE, 500.0, 350.0);
Chart chart = shape.getChart();
Assert.assertEquals(1, chart.getSeries().getCount());
Assert.assertEquals("Sales", chart.getSeries().get(0).getName());
// "Slices" of a pie chart may be moved away from the center by a distance via the respective data point's Explosion attribute.
// Add a data point to the first portion of the pie chart and move it away from the center by 10 points.
// Aspose.Words create data points automatically if them does not exist.
ChartDataPoint dataPoint = chart.getSeries().get(0).getDataPoints().get(0);
dataPoint.setExplosion(10);
// Displace the second portion by a greater distance.
dataPoint = chart.getSeries().get(0).getDataPoints().get(1);
dataPoint.setExplosion(40);
doc.save(getArtifactsDir() + "Charts.PieChartExplosion.docx");
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | int | The corresponding int value. |
setInvertIfNegative(boolean value)
public void setInvertIfNegative(boolean value)
Specifies whether the parent element shall inverts its colors if the value is negative.
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 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");
}
///
/// Applies a number of data points to a series.
///
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);
}
}
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | boolean | The corresponding boolean value. |
setShapeType(int value)
public void setShapeType(int value)
Parameters:
| Parameter | Type | Description |
|---|---|---|
| value | int |