Skip to main content

Chart Class

A standard chart (for example, a bar, line, or pie chart) on a slide.

Declaration

public class Chart extends ChartBase

Remarks

Add series to the Chart.getSeries() collection to populate a chart with data. The series type specifies the chart type. For example, a BarSeries creates a bar chart. The ChartType enumeration lists available chart types.

When you add series, the chart creates chart views (Chart.getViews()) and axes that these series require.

To create a chart of a type introduced in Microsoft Excel 2016 (for example, a waterfall or treemap chart), use the ChartEx class.

Refer to the following help topics for additional information:

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:

 Column chart with the Quarterly Sales title created with the DevExpress Presentation API for Java

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

See Also

Constructors

Chart() Constructor

Initializes a new instance of the Chart class.

Declaration

public Chart()

Remarks

If you do not specify the chart width or height, the API sets the width to 600 and the height to 400 Document units (1/300 inch).

Chart(float x, float y, float width, float height) Constructor

Initializes a new instance of the Chart class with the specified position and size.

Declaration

public Chart(float x, float y, float width, float height)

Parameters

Name Type Description
x float

The horizontal position of the chart.

y float

The vertical position of the chart.

width float

The chart width.

height float

The chart height.

Chart(float x, float y, float width) Constructor

Initializes a new instance of the Chart class with the specified position and width.

Declaration

public Chart(float x, float y, float width)

Parameters

Name Type Description
x float

The horizontal position of the chart.

y float

The vertical position of the chart.

width float

The chart width.

Remarks

If you do not specify the chart width or height, the API sets the width to 600 and the height to 400 Document units (1/300 inch).

Chart(float x, float y) Constructor

Initializes a new instance of the Chart class with the specified position.

Declaration

public Chart(float x, float y)

Parameters

Name Type Description
x float

The horizontal position of the chart.

y float

The vertical position of the chart.

Remarks

If you do not specify the chart width or height, the API sets the width to 600 and the height to 400 Document units (1/300 inch).

Chart(float x) Constructor

Initializes a new instance of the Chart class with the specified horizontal position.

Declaration

public Chart(float x)

Parameters

Name Type Description
x float

The horizontal position of the chart.

Remarks

If you do not specify the chart width or height, the API sets the width to 600 and the height to 400 Document units (1/300 inch).

Methods

deepClone() Method

Creates a copy of the chart.

Declaration

public Chart deepClone()

Returns

Type Description
Chart

A copy of the chart.

Remarks

The copy contains series, views, axes, title, legend, and other chart settings. To display the copy, add it to the shape collection of a slide (SlideBase.getShapes()).

getArgumentAxis() Method

Returns the primary argument axis.

Declaration

public Axis getArgumentAxis()

Returns

Type Description
Axis

The primary argument axis, or null if the chart has no argument axis (for example, a pie chart).

getDataTable() Method

Returns data table settings for the chart.

Declaration

public DataTableOptions getDataTable()

Returns

Type Description
DataTableOptions

Data table settings, or null if the chart does not display a data table.

getLegend() Method

Returns the chart legend.

Declaration

public Legend getLegend()

Returns

Type Description
Legend

The chart legend, or null if the chart does not display a legend.

getOptions() Method

Returns chart display options.

Declaration

public ChartOptions getOptions()

Returns

Type Description
ChartOptions

Chart display options.

Remarks

The ChartOptions object contains chart-level display settings (for example, how the chart displays blank cells and whether the chart area has rounded corners).

getSecondaryArgumentAxis() Method

Returns the secondary argument axis.

Declaration

public Axis getSecondaryArgumentAxis()

Returns

Type Description
Axis

The secondary argument axis, or null if the chart has no secondary argument axis.

getSecondaryValueAxis() Method

Returns the secondary value axis.

Declaration

public ValueAxis getSecondaryValueAxis()

Returns

Type Description
ValueAxis

The secondary value axis, or null if the chart has no secondary value axis.

getSeries() Method

Returns the collection of chart series.

Declaration

public ISeriesCollection getSeries()

Returns

Type Description
ISeriesCollection

The collection of chart series.

Remarks

When you add a series, the chart creates a view for the series type and axis group and creates axes that the view requires. When you remove the last series in a view, the chart removes this view.

Series in the same axis group must use the same axis types. For example, you cannot combine a scatter series and a bar series in one axis group. If a series is incompatible with other chart series, the API throws an InvalidOperationException.

Refer to the following help topic for additional information: Create Combo Charts — Presentation API for Java.

getSeriesAxis() Method

Returns the series (depth) axis of a 3D chart.

Declaration

public SeriesAxis getSeriesAxis()

Returns

Type Description
SeriesAxis

The series axis, or null if the chart has no series axis.

getStyle() Method

Returns the chart style.

Declaration

public ChartStyle getStyle()

Returns

Type Description
ChartStyle

The chart style.

getTextProperties() Method

Returns text formatting settings that apply to all chart text elements.

Declaration

public TextProperties getTextProperties()

Returns

Type Description
TextProperties

Text formatting settings, or null if the chart has no chart-level text formatting settings.

getTitle() Method

Returns the chart title.

Declaration

public ChartTitle getTitle()

Returns

Type Description
ChartTitle

The chart title, or null if the chart does not display a title.

getValueAxis() Method

Returns the primary value axis.

Declaration

public ValueAxis getValueAxis()

Returns

Type Description
ValueAxis

The primary value axis, or null if the chart has no value axis (for example, a pie chart).

getView3D() Method

Returns 3D view settings for the chart.

Declaration

public View3DOptions getView3D()

Returns

Type Description
View3DOptions

3D view settings, or null if the chart has no 3D view settings (for example, a chart that contains 2D series).

getViews() Method

Returns the collection of chart views.

Declaration

public IChartViewCollection getViews()

Returns

Type Description
IChartViewCollection

The collection of chart views.

Remarks

A chart view combines series of the same type in the same axis group and stores settings that apply to all series in the view. For example, a BarChartView specifies bar direction, grouping, gap width, and overlap for bar series.

The chart creates and removes views when you add and remove series. Cast a view to a specific view type to configure view settings.

setArgumentAxis(Axis value) Method

Sets the primary argument axis.

Declaration

public void setArgumentAxis(Axis value)

Parameters

Name Type Description
value Axis

The primary argument axis.

Exceptions

Type Description
InvalidOperationException

Thrown if you call the setArgumentAxis(null) method while the chart contains series that use the primary argument axis. Also thrown if the axis type is not compatible with the chart type (for example, a value axis for a bar chart or a category axis for a scatter chart). The exception message is “A null axis cannot be assigned while the chart view is active.” or “Views with incompatible axis types cannot share an axis group.”

Remarks

When you add series that require axes, the chart creates the primary argument axis. For example, the chart creates a category axis (CategoryAxis) for bar series and a value axis (ValueAxis) for scatter series.

You can pass a CategoryAxis, DateAxis, or ValueAxis object to the setArgumentAxis(value) method. If you assign an axis before the chart contains series that require axes, the chart stores the axis and applies it when you add a compatible series.

Refer to the following help topic for additional information: Customize Chart Axes — Presentation API for Java.

setDataTable(DataTableOptions value) Method

Sets data table settings for the chart.

Declaration

public void setDataTable(DataTableOptions value)

Parameters

Name Type Description
value DataTableOptions

Data table settings, or null to hide the data table.

Remarks

A data table displays chart data in a grid below the plot area. A new chart does not display a data table. To display a data table, pass a DataTableOptions object to the setDataTable(value) method.

setLegend(Legend value) Method

Sets the chart legend.

Declaration

public void setLegend(Legend value)

Parameters

Name Type Description
value Legend

The chart legend, or null to hide the legend.

Remarks

A new chart displays a legend. To hide the legend, call the setLegend(null) method.

Refer to the following help topic for additional information: Customize Chart Legends — Presentation API for Java.

setSecondaryArgumentAxis(Axis value) Method

Sets the secondary argument axis.

Declaration

public void setSecondaryArgumentAxis(Axis value)

Parameters

Name Type Description
value Axis

The secondary argument axis.

Exceptions

Type Description
InvalidOperationException

Thrown if you call the setSecondaryArgumentAxis(null) method while the chart contains series in the secondary axis group. Also thrown if the axis type is not compatible with the chart type (for example, a value axis for a bar chart). The exception message is “A null axis cannot be assigned while the chart view is active.” or “Views with incompatible axis types cannot share an axis group.”

Remarks

The chart creates secondary axes when you add a series in the secondary axis group (ChartAxisGroupType.SECONDARY). If you assign a secondary argument axis before the chart contains such series, the chart stores the axis and applies it when you add a compatible series.

Refer to the following help topic for additional information: Customize Chart Axes — Presentation API for Java.

setSecondaryValueAxis(ValueAxis value) Method

Sets the secondary value axis.

Declaration

public void setSecondaryValueAxis(ValueAxis value)

Parameters

Name Type Description
value ValueAxis

The secondary value axis.

Exceptions

Type Description
InvalidOperationException

Thrown if you call the setSecondaryValueAxis(null) method while the chart contains series in the secondary axis group. The exception message is “A null axis cannot be assigned while the chart view is active.”

Remarks

The chart creates secondary axes when you add a series in the secondary axis group (ChartAxisGroupType.SECONDARY). If you assign a secondary value axis before the chart contains such series, the chart stores the axis and applies it when you add a compatible series.

Refer to the following help topic for additional information: Customize Chart Axes — Presentation API for Java.

setSeriesAxis(SeriesAxis value) Method

Sets the series (depth) axis of a 3D chart.

Declaration

public void setSeriesAxis(SeriesAxis value)

Parameters

Name Type Description
value SeriesAxis

The series axis.

Exceptions

Type Description
InvalidOperationException

Thrown if the chart contains series that do not use a series axis (for example, bar series). Also thrown if you call the setSeriesAxis(null) method while the chart contains series that use the series axis. The exception message is “Views with incompatible axis types cannot share an axis group.”

Remarks

The chart creates a series axis for 3D chart types that have three axes (for example, 3D line charts). If you assign a series axis before the chart contains series, the chart stores the axis and applies it when you add a series that requires three axes. If you add another series type (for example, a bar series), the API throws an InvalidOperationException.

Refer to the following help topic for additional information: Customize Chart Axes — Presentation API for Java.

setStyle(ChartStyle value) Method

Sets the chart style.

Declaration

public void setStyle(ChartStyle value)

Parameters

Name Type Description
value ChartStyle

The chart style.

Exceptions

Type Description
ArgumentNullException

Thrown if the value parameter is null.

Remarks

A new chart uses the ChartStyle.COLOR style.

setTextProperties(TextProperties value) Method

Sets text formatting settings that apply to all chart text elements.

Declaration

public void setTextProperties(TextProperties value)

Parameters

Name Type Description
value TextProperties

Text formatting settings.

Remarks

To specify text formatting settings for an individual chart element, call the element’s method (for example, Legend.setTextProperties(value) or Axis.setLabelTextProperties(value)).

setTitle(ChartTitle value) Method

Sets the chart title.

Declaration

public void setTitle(ChartTitle value)

Parameters

Name Type Description
value ChartTitle

The chart title, or null to hide the title.

Remarks

A new chart does not display a title. To display a title, pass a ChartTitle object to the setTitle(value) method.

setValueAxis(ValueAxis value) Method

Sets the primary value axis.

Declaration

public void setValueAxis(ValueAxis value)

Parameters

Name Type Description
value ValueAxis

The primary value axis.

Exceptions

Type Description
InvalidOperationException

Thrown if you call the setValueAxis(null) method while the chart contains series that use the primary value axis. The exception message is “A null axis cannot be assigned while the chart view is active.”

Remarks

The chart creates the primary value axis when you add series that require axes. If you assign a value axis before the chart contains such series, the chart stores the axis and applies it when you add a compatible series.

Refer to the following help topic for additional information: Customize Chart Axes — Presentation API for Java.

setView3D(View3DOptions value) Method

Sets 3D view settings for the chart.

Declaration

public void setView3D(View3DOptions value)

Parameters

Name Type Description
value View3DOptions

3D view settings, or null to use default 3D view settings.

Remarks

The chart applies 3D view settings when it displays 3D series (for example, Bar3DSeries or Line3DSeries). If the chart displays 2D series, the API ignores 3D view settings.

A View3DOptions object specifies chart rotation, perspective, depth, and floor and wall formatting.