Skip to main content

ChartBase Class

The base class for chart shapes.

Declaration

public abstract class ChartBase extends ShapeBase

Remarks

A chart is a shape. Call the SlideBase.getShapes() method to access charts on a slide.

Refer to the following help topic for additional information: Create and Customize Charts — 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

Methods

getData() Method

Returns chart data.

Declaration

public ChartData getData()

Returns

Type Description
ChartData

Chart data.

Remarks

Chart data stores cell values that chart series refer to. Call the ChartData.get(cellReference) method or another ChartData.get method overload to access cells (ChartCellValue objects) and specify cell values. Cell addresses use A1 notation.

To bind series to cells, pass a ChartDataReference object to a series method (for example, SeriesBase.setValues(value) or SeriesBase.setArguments(value)).

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:

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

getFill() Method

Returns the fill applied to the chart background.

Declaration

public Fill getFill()

Returns

Type Description
Fill

The fill applied to the chart background.

getOutlineStyle() Method

Returns chart outline settings.

Declaration

public OutlineStyle getOutlineStyle()

Returns

Type Description
OutlineStyle

Outline settings.

getPlotArea() Method

Returns plot area settings.

Declaration

public PlotArea getPlotArea()

Returns

Type Description
PlotArea

Plot area settings.

setFill(Fill value) Method

Sets the fill applied to the chart background.

Declaration

public void setFill(Fill value)

Parameters

Name Type Description
value Fill

The fill applied to the chart background.

setOutlineStyle(OutlineStyle value) Method

Sets chart outline settings.

Declaration

public void setOutlineStyle(OutlineStyle value)

Parameters

Name Type Description
value OutlineStyle

Outline settings.

setPlotArea(PlotArea value) Method

Sets plot area settings.

Declaration

public void setPlotArea(PlotArea value)

Parameters

Name Type Description
value PlotArea

Plot area settings.