ChartDataReference Class
A cell, range, or union of ranges that contains chart data.
Declaration
public class ChartDataReference extends JavaObject implements IChartValueData, IChartArgumentData, IChartDataReference
Remarks
Pass a ChartDataReference object to a series method (for example, DataSeriesExBase.setValues(value)) to bind series values or arguments to chart data cells. Call the ChartData.get(reference) method to access cells in a data reference.
Call the union(ChartDataReference other) method to combine references on the same sheet.
Refer to the following help topic for additional information: Load Data into Charts — Presentation API for Java.
Example
Create a Bar Chart with a Title
The following code snippet adds a bar chart to a slide, binds the series to chart data, and adds a chart title:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;
import com.devexpress.system.drawing.*;
public class Main {
public static void main(String[] args) throws Exception {
try (Presentation presentation = new Presentation()) {
// Add a blank slide.
presentation.getSlides().clear();
Slide slide = new Slide(SlideLayoutType.BLANK);
presentation.getSlides().add(slide);
// Insert a chart that fills the slide.
Chart chart = new Chart();
chart.setWidth(presentation.getSlideSize().getWidth());
chart.setHeight(presentation.getSlideSize().getHeight());
slide.getShapes().add(chart);
// Populate chart data.
ChartData data = chart.getData();
data.get(0, "A1").setNumericValue(120);
data.get(0, "A2").setNumericValue(95);
data.get(0, "A3").setNumericValue(140);
data.get(0, "B1").setTextValue("Q1");
data.get(0, "B2").setTextValue("Q2");
data.get(0, "B3").setTextValue("Q3");
// Bind series values and arguments to chart data ranges.
BarSeries series = new BarSeries();
series.setValues(new ChartDataReference(0, "A1", "A3"));
series.setArguments(new ChartDataReference(0, "B1", "B3"));
chart.getSeries().add(series);
// Add a chart title.
TextProperties titleTextProperties = new TextProperties();
titleTextProperties.setFontSize(30f);
titleTextProperties.setFill(new SolidFill(Color.getDarkBlue()));
chart.setTitle(new ChartTitle(
new TextArea("Quarterly Sales", new TextParagraphProperties(titleTextProperties))));
// Save the presentation.
Files.createDirectories(Path.of("output"));
try (OutputStream output = Files.newOutputStream(Path.of("output", "Chart.pptx"))) {
presentation.save(output);
}
}
}
}
The following screenshot illustrates the result:

Inherited Members
Inheritance
Constructors
ChartDataReference(CellPosition topPosition, CellPosition bottomPosition) Constructor
Initializes a new instance of the ChartDataReference class with the specified range on the first sheet.
Declaration
public ChartDataReference(CellPosition topPosition, CellPosition bottomPosition)
Parameters
| Name | Type | Description |
|---|---|---|
| topPosition | CellPosition | A corner cell of the range. |
| bottomPosition | CellPosition | The opposite corner cell of the range. |
Remarks
The data reference points to cells on the first sheet (index 0). You can specify range corners in any order. The getTopLeftPosition() method returns the top-left cell of the range.
ChartDataReference(int sheetIndex, CellPosition topPosition, CellPosition bottomPosition) Constructor
Initializes a new instance of the ChartDataReference class with the specified range on the specified sheet.
Declaration
public ChartDataReference(int sheetIndex, CellPosition topPosition, CellPosition bottomPosition)
Parameters
| Name | Type | Description |
|---|---|---|
| sheetIndex | int | The zero-based index of the chart data sheet. |
| topPosition | CellPosition | A corner cell of the range. |
| bottomPosition | CellPosition | The opposite corner cell of the range. |
Remarks
You can specify range corners in any order. The getTopLeftPosition() method returns the top-left cell of the range.
ChartDataReference(int sheetIndex, String cellReference) Constructor
Initializes a new instance of the ChartDataReference class with the specified cell on the specified sheet.
Declaration
public ChartDataReference(int sheetIndex, String cellReference)
Parameters
| Name | Type | Description |
|---|---|---|
| sheetIndex | int | The zero-based index of the chart data sheet. |
| cellReference | String | The cell address in A1 notation. |
Exceptions
| Type | Description |
|---|---|
| ArgumentException | Thrown if the |
| NullPointerException | Thrown if the |
ChartDataReference(int sheetIndex, String fromCellReference, String toCellReference) Constructor
Initializes a new instance of the ChartDataReference class with the specified range on the specified sheet.
Declaration
public ChartDataReference(int sheetIndex, String fromCellReference, String toCellReference)
Parameters
| Name | Type | Description |
|---|---|---|
| sheetIndex | int | The zero-based index of the chart data sheet. |
| fromCellReference | String | The address of a corner cell of the range in A1 notation. |
| toCellReference | String | The address of the opposite corner cell in A1 notation. |
Exceptions
| Type | Description |
|---|---|
| ArgumentException | Thrown if the |
| NullPointerException | Thrown if the |
Remarks
You can specify range corners in any order. The getTopLeftPosition() method returns the top-left cell of the range.
ChartDataReference(String cellReference) Constructor
Initializes a new instance of the ChartDataReference class with the specified cell on the first sheet.
Declaration
public ChartDataReference(String cellReference)
Parameters
| Name | Type | Description |
|---|---|---|
| cellReference | String | The cell address in A1 notation. |
Exceptions
| Type | Description |
|---|---|
| ArgumentException | Thrown if the |
| NullPointerException | Thrown if the |
Remarks
The data reference points to cells on the first sheet (index 0).
ChartDataReference(String fromCellReference, String toCellReference) Constructor
Initializes a new instance of the ChartDataReference class with the specified range on the first sheet.
Declaration
public ChartDataReference(String fromCellReference, String toCellReference)
Parameters
| Name | Type | Description |
|---|---|---|
| fromCellReference | String | The address of a corner cell of the range in A1 notation. |
| toCellReference | String | The address of the opposite corner cell in A1 notation. |
Exceptions
| Type | Description |
|---|---|
| ArgumentException | Thrown if the |
| NullPointerException | Thrown if the |
Remarks
The data reference points to cells on the first sheet (index 0). You can specify range corners in any order. The getTopLeftPosition() method returns the top-left cell of the range.
Methods
cloneArgumentData() Method
Creates a copy of the data reference.
Declaration
public IChartArgumentData cloneArgumentData()
Returns
| Type | Description |
|---|---|
| IChartArgumentData | A copy of the data reference. |
cloneReference() Method
Creates a copy of the data reference.
Declaration
public IChartDataReference cloneReference()
Returns
| Type | Description |
|---|---|
| IChartDataReference | A copy of the data reference. |
cloneValueData() Method
Creates a copy of the data reference.
Declaration
public IChartValueData cloneValueData()
Returns
| Type | Description |
|---|---|
| IChartValueData | A copy of the data reference. |
contains(ChartDataReference other) Method
Returns whether the data reference contains all cells of the specified data reference.
Declaration
public boolean contains(ChartDataReference other)
Parameters
| Name | Type | Description |
|---|---|---|
| other | ChartDataReference |
The data reference to check. |
Returns
| Type | Description |
|---|---|
| boolean |
|
Remarks
The contains method compares cell positions only and does not compare sheet indexes.
contains(int rowIndex, int columnIndex) Method
Returns whether the data reference contains the specified cell.
Declaration
public boolean contains(int rowIndex, int columnIndex)
Parameters
| Name | Type | Description |
|---|---|---|
| rowIndex | int | The zero-based row index. |
| columnIndex | int | The zero-based column index. |
Returns
| Type | Description |
|---|---|
| boolean |
|
exclude(ChartDataReference other) Method
Returns a data reference that contains cells of this data reference except cells of the specified data reference.
Declaration
public ChartDataReference exclude(ChartDataReference other)
Parameters
| Name | Type | Description |
|---|---|---|
| other | ChartDataReference |
The data reference with cells to exclude. |
Returns
| Type | Description |
|---|---|
ChartDataReference |
A data reference that contains the remaining cells (the current data reference if the references do not intersect), or |
Remarks
The exclude method does not modify the current data reference. If the other reference is on another sheet, the exclude method returns the current data reference.
getBottomRightPosition() Method
Returns the bottom-right cell of the data reference bounds.
Declaration
public CellPosition getBottomRightPosition()
Returns
| Type | Description |
|---|---|
| CellPosition | The bottom-right cell position. |
Remarks
If the data reference is a union of ranges, the bounds include all ranges.
getCellCount() Method
Returns the number of cells in the data reference.
Declaration
public int getCellCount()
Returns
| Type | Description |
|---|---|
| int | The number of cells. |
Remarks
If the data reference is a union of ranges, the getCellCount() method returns the total number of cells in these ranges. The getCellCount() method does not count cells between the ranges.
getColumnCount() Method
Returns the number of columns in the data reference bounds.
Declaration
public int getColumnCount()
Returns
| Type | Description |
|---|---|
| int | The number of columns. |
Remarks
If the data reference is a union of ranges, the bounds include all ranges.
getExpression(IChartDataContext context) Method
Returns the data reference expression in A1 notation.
Declaration
public String getExpression(IChartDataContext context)
Parameters
| Name | Type | Description |
|---|---|---|
| context | IChartDataContext | An object that returns sheet names for sheet indexes. |
Returns
| Type | Description |
|---|---|
| String | The data reference expression (for example, Sheet1!$A$1:$B$3). |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if the |
Remarks
The expression contains absolute cell references. If the context object returns no sheet name for the sheet index, the expression does not contain a sheet name (for example, $A$1:$B$3). The expression encloses sheet names that contain spaces in single quotes (for example, ‘My Sheet’!$A$1:$B$3).
If the data reference is a union of ranges, the expression lists the ranges in parentheses (for example, (Sheet1!$A$1:$A$3,Sheet1!$C$1:$C$3)).
getIsCell() Method
Returns whether the data reference points to a single cell.
Declaration
public boolean getIsCell()
Returns
| Type | Description |
|---|---|
| boolean |
|
Remarks
A data reference created with the ChartDataReference(fromCellReference, toCellReference) constructor is a range, even if both addresses point to the same cell.
getIsEmpty() Method
Returns whether the data reference contains no cells.
Declaration
public boolean getIsEmpty()
Returns
| Type | Description |
|---|---|
| boolean |
|
getIsRange() Method
Returns whether the data reference points to a rectangular range.
Declaration
public boolean getIsRange()
Returns
| Type | Description |
|---|---|
| boolean |
|
getIsUnion() Method
Returns whether the data reference is a union of ranges.
Declaration
public boolean getIsUnion()
Returns
| Type | Description |
|---|---|
| boolean |
|
getLevelCount() Method
Returns the number of argument levels in the data object.
Declaration
public int getLevelCount()
Returns
| Type | Description |
|---|---|
| int |
|
Remarks
A data reference does not store values. Chart data cells that the data reference points to contain the values.
getNumericValues() Method
Returns numeric values stored in the data object.
Declaration
public List<Double> getNumericValues()
Returns
| Type | Description |
|---|---|
| java.util.List<java.lang.Double> |
|
Remarks
A data reference does not store values. Chart data cells that the data reference points to contain the values.
getRowCount() Method
Returns the number of rows in the data reference bounds.
Declaration
public int getRowCount()
Returns
| Type | Description |
|---|---|
| int | The number of rows. |
Remarks
If the data reference is a union of ranges, the bounds include all ranges.
getSheetIndex() Method
Returns the index of the chart data sheet that contains the referenced cells.
Declaration
public int getSheetIndex()
Returns
| Type | Description |
|---|---|
| int | The zero-based sheet index. |
getTopLeftPosition() Method
Returns the top-left cell of the data reference bounds.
Declaration
public CellPosition getTopLeftPosition()
Returns
| Type | Description |
|---|---|
| CellPosition | The top-left cell position. |
Remarks
If the data reference is a union of ranges, the bounds include all ranges.
getType() Method
Returns the chart data type.
Declaration
public ChartDataType getType()
Returns
| Type | Description |
|---|---|
| ChartDataType |
|
intersectsWith(ChartDataReference other) Method
Returns whether the data reference shares at least one cell with the specified data reference.
Declaration
public boolean intersectsWith(ChartDataReference other)
Parameters
| Name | Type | Description |
|---|---|---|
| other | ChartDataReference |
The data reference to check. |
Returns
| Type | Description |
|---|---|
| boolean |
|
Remarks
Data references on different sheets do not intersect.
union(ChartDataReference other) Method
Returns a data reference that contains cells of this data reference and the specified data reference.
Declaration
public ChartDataReference union(ChartDataReference other)
Parameters
| Name | Type | Description |
|---|---|---|
| other | ChartDataReference |
The data reference to combine with the current data reference. |
Returns
| Type | Description |
|---|---|
ChartDataReference |
A new data reference that contains cells of both data references. |
Exceptions
| Type | Description |
|---|---|
| ArgumentException | Thrown if the |
Remarks
The union method does not modify the current data reference. The new data reference contains each cell once, even if the data references overlap.