Skip to main content

Create Standard Charts — Presentation API for Java

  • 18 minutes to read

The Presentation API allows you to create standard charts on slides (bar, column, line, area, pie, doughnut, scatter, bubble, radar, stock, and surface charts and their 3D variants).

A standard chart is a Chart object. The series objects that you add to the chart determine the chart type.

 Bar, line, pie, area, doughnut, and 3D column charts created with the DevExpress Presentation API for Java

Create a Standard Chart

Follow the steps below to add a standard chart to a slide:

  1. Create a Chart object and specify the chart position and size.
  2. Add the chart to the SlideBase.getShapes() collection.
  3. Create series objects (for example, BarSeries objects) and specify series data.
  4. Add the series to the Chart.getSeries() collection.

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

Configure Chart Views

A standard chart displays series in chart views. When you add a series, the chart creates a view for the series type and axis group. A view stores settings that apply to all series in the view (for example, the bar grouping in a bar chart).

Call the Chart.getViews() method to access chart views. To configure a view, cast the view to the view class from the following table:

Chart Type Series Class View Class
Area AreaSeries AreaChartView
3D area Area3DSeries Area3DChartView
Bar and column BarSeries BarChartView
3D bar and column Bar3DSeries Bar3DChartView
Bubble BubbleSeries BubbleChartView
Doughnut DoughnutSeries DoughnutChartView
Line LineSeries LineChartView
3D line Line3DSeries Line3DChartView
Pie PieSeries PieChartView
3D pie Pie3DSeries Pie3DChartView
Pie of pie and bar of pie ChartOfPieSeries ChartOfPieView
Radar RadarSeries RadarChartView
Scatter ScatterSeries ScatterChartView
Stock StockSeries StockChartView
Surface SurfaceSeries SurfaceChartView
3D surface Surface3DSeries Surface3DChartView

A chart with series of multiple chart types or axis groups (a combo chart) contains multiple views.

Bar and Column Charts

Add BarSeries objects to a chart to create a bar or column chart. Call the following methods to configure the chart view:

Method Description
BarChartView.setBarDirection(value) Sets the bar orientation (vertical columns or horizontal bars).
BarChartView.setBarGrouping(value) Sets the bar grouping type.
BarChartView.setGapWidth(value) Sets the gap width between categories.
BarChartView.setOverlap(value) Sets the overlap of bars in a category.

The following code snippet displays chart series as horizontal stacked bars:

// Access the view that the chart created for bar series.
BarChartView view = (BarChartView) chart.getViews().get(0);
view.setBarDirection(BarChartDirection.BAR);
view.setBarGrouping(BarChartGrouping.STACKED);
// Place bars of different series in a category on top of each other.
view.setOverlap(100);

Line Charts

Add LineSeries objects to a chart to create a line chart. Call the following methods to configure line series and the chart view:

Method Description
LineSeries.setMarker(value) Sets marker settings for series data points.
LineSeries.setSmooth(value) Sets whether the series connects data points with smooth lines.
LineChartView.setGrouping(value) Sets the series grouping type.

The following code snippet creates a line chart with two series, displays circle markers, smooths the second line, and displays a data label for the last data point of the first series:

import java.io.*;
import java.nio.file.*;
import java.util.List;
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);

            // Add two line series with circle markers.
            String[] names = { "2024", "2025" };
            double[][] values = { { 12, 18, 15, 21 }, { 14, 16, 22, 25 } };
            for (int i = 0; i < names.length; i++) {
                LineSeries series = new LineSeries();
                series.setText(names[i]);
                series.setArguments(new ChartStringData(List.of("Q1", "Q2", "Q3", "Q4")));
                series.setValues(new ChartNumericData(List.of(values[i][0], values[i][1], values[i][2], values[i][3])));
                Marker marker = new Marker();
                marker.setSymbol(MarkerStyle.CIRCLE);
                marker.setSize(8);
                series.setMarker(marker);
                chart.getSeries().add(series);
            }

            // Smooth the second line.
            LineSeries secondSeries = (LineSeries) chart.getSeries().get(1);
            secondSeries.setSmooth(true);

            // Display the Q4 value of the first series above the data point.
            LineDataLabel label = new LineDataLabel();
            label.setShowValue(true);
            label.setLabelPosition(LineDataLabelPosition.TOP);
            LineSeries firstSeries = (LineSeries) chart.getSeries().get(0);
            firstSeries.getDataLabels().setLabel(3, label);

            // 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:

 Line chart with circle markers, a smooth line, and a data label created with the DevExpress Presentation API for Java

Area Charts

Add AreaSeries objects to a chart to create an area chart. Call the following methods to configure the chart view:

Method Description
AreaChartView.setGrouping(value) Sets the series grouping type.
AreaChartView.setShowDropLines(value) Sets whether to display drop lines.

The following code snippet creates an area chart, displays values in data labels, and applies bold text formatting to the last data label:

import java.io.*;
import java.nio.file.*;
import java.util.List;
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);

            // Add an area series.
            AreaSeries series = new AreaSeries();
            series.setText("Visitors");
            series.setArguments(new ChartStringData(List.of("Jan", "Feb", "Mar", "Apr", "May")));
            series.setValues(new ChartNumericData(List.of(320.0, 410.0, 380.0, 520.0, 610.0)));
            chart.getSeries().add(series);

            // Fill the area and display values in data labels.
            ChartElement properties = new ChartElement();
            properties.setFill(new SolidFill(Color.getSeaGreen()));
            series.setProperties(properties);
            series.getDataLabels().setShowValue(true);

            // Apply bold text formatting to the last data label.
            TextProperties boldText = new TextProperties();
            boldText.setBold(true);
            AreaDataLabel lastLabel = new AreaDataLabel();
            lastLabel.setShowValue(true);
            lastLabel.setTextProperties(boldText);
            series.getDataLabels().setLabel(4, lastLabel);

            // 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:

 Area chart with data labels and a bold last label created with the DevExpress Presentation API for Java

Pie and Doughnut Charts

Add a PieSeries object to a chart to create a pie chart. Add DoughnutSeries objects to create a doughnut chart. Call the following methods to configure pie and doughnut charts:

Method Description
PieSeries.setExplosion(value) Sets the distance between slices and the chart center.
PieChartView.setFirstSliceAngle(value) Sets the angle of the first slice.
PieChartView.setVaryColors(value) Sets whether data points in the view use different colors.
DoughnutChartView.setHoleSize(value) Sets the size of the doughnut hole as a percentage of the doughnut size.

The following code snippet creates a pie chart, pulls the first slice out of the pie, displays category names and percentages in data labels, and applies bold text formatting to the first data label:

import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

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);

            // Create a pie series and specify data.
            PieSeries series = new PieSeries();
            series.setText("Budget");
            series.setArguments(new ChartStringData(List.of("Salaries", "Marketing", "Rent", "Equipment", "Travel")));
            series.setValues(new ChartNumericData(List.of(48.0, 20.0, 15.0, 10.0, 7.0)));
            chart.getSeries().add(series);

            // Pull the first slice out of the pie.
            DataPoint salaries = new DataPoint();
            salaries.setExplosion(15);
            series.getCustomDataPoints().put(0, salaries);

            // Color each slice differently.
            PieChartView view = (PieChartView) chart.getViews().get(0);
            view.setVaryColors(true);

            // Display category names and percentages outside slices.
            IPieDataLabels dataLabels = series.getDataLabels();
            dataLabels.setShowCategoryName(true);
            dataLabels.setShowPercent(true);
            dataLabels.setLabelPosition(PieDataLabelPosition.OUTSIDE_END);

            // Apply bold text formatting to the data label of the first slice.
            TextProperties boldText = new TextProperties();
            boldText.setBold(true);
            PieDataLabel salariesLabel = new PieDataLabel();
            salariesLabel.setShowCategoryName(true);
            salariesLabel.setShowPercent(true);
            salariesLabel.setLabelPosition(PieDataLabelPosition.OUTSIDE_END);
            salariesLabel.setTextProperties(boldText);
            dataLabels.setLabel(0, salariesLabel);

            // 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:

 Pie chart with an exploded slice and percentages in data labels created with the DevExpress Presentation API for Java

The following code snippet creates a doughnut chart, separates the slices, enlarges the doughnut hole, and displays category names and percentages in data labels:

import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

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);

            // Create a doughnut series and specify data.
            DoughnutSeries series = new DoughnutSeries();
            series.setText("Market Share");
            series.setArguments(new ChartStringData(List.of("Product A", "Product B", "Product C", "Product D")));
            series.setValues(new ChartNumericData(List.of(45.0, 25.0, 18.0, 12.0)));
            series.setExplosion(0.05f);
            chart.getSeries().add(series);

            // Enlarge the hole, rotate slices, and color each slice differently.
            DoughnutChartView view = (DoughnutChartView) chart.getViews().get(0);
            view.setHoleSize(50);
            view.setFirstSliceAngle(90);
            view.setVaryColors(true);

            // Display category names and percentages in data labels.
            view.getDataLabels().setShowCategoryName(true);
            view.getDataLabels().setShowPercent(true);

            // 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:

 Doughnut chart with separated slices and percentages in data labels created with the DevExpress Presentation API for Java

Pie of Pie and Bar of Pie Charts

Add a ChartOfPieSeries object to a chart to create a pie of pie or bar of pie chart. Call the following methods to configure the secondary plot:

Method Description
setSecondChartType(ChartOfPieType value) Sets the type of the secondary plot.
setSplitType(ChartOfPieSplitType value) Sets the method that determines data points in the secondary plot.
setSplitPosition(double value) Sets the threshold that determines data points in the secondary plot.
setSecondPlotSize(int value) Sets the size of the secondary plot as a percentage of the main pie size.

The following code snippet creates a bar of pie chart that moves data points with values less than 15 to a secondary bar and connects the plots with series lines:

import java.io.*;
import java.nio.file.*;
import java.util.List;
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);

            // Create a series for a bar of pie chart.
            ChartOfPieSeries series = new ChartOfPieSeries();
            series.setText("Sales by Region");
            series.setArguments(new ChartStringData(List.of("North", "South", "East", "West", "Online", "Partners")));
            series.setValues(new ChartNumericData(List.of(32.0, 25.0, 21.0, 12.0, 6.0, 4.0)));
            chart.getSeries().add(series);

            // Move data points with values less than 15 to a secondary bar.
            ChartOfPieView view = (ChartOfPieView) chart.getViews().get(0);
            view.setSecondChartType(ChartOfPieType.BAR);
            view.setSplitType(ChartOfPieSplitType.VALUE);
            view.setSplitPosition(15);
            view.setGapWidth(80);
            view.setVaryColors(true);

            // Draw gray series lines between the plots.
            OutlineStyle seriesLine = new OutlineStyle();
            seriesLine.setFill(new SolidFill(Color.getGray()));
            ChartElement seriesLineProperties = new ChartElement();
            seriesLineProperties.setOutlineStyle(seriesLine);
            view.setSeriesLineProperties(seriesLineProperties);

            // Display category names and values in data labels.
            view.getDataLabels().setShowCategoryName(true);
            view.getDataLabels().setShowValue(true);

            // 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:

 Bar of pie chart with series lines and category names in data labels created with the DevExpress Presentation API for Java

Scatter and Bubble Charts

Add ScatterSeries objects to a chart to create a scatter chart. Scatter series display numeric arguments (X values) and values (Y values). Call the following methods to configure scatter series and the chart view:

Method Description
ScatterChartView.setStyle(value) Sets the scatter chart style.
ScatterSeries.setMarker(value) Sets marker settings for series data points.

The following code snippet creates a scatter chart that displays circle markers without lines, adds a linear trend line, and displays data labels above data points:

import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

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);

            // Create a scatter series: advertising spend (X) and sales (Y).
            ScatterSeries series = new ScatterSeries();
            series.setText("Sales");
            series.setArguments(new ChartNumericData(List.of(1.0, 2.0, 3.0, 4.0, 5.0, 6.0)));
            series.setValues(new ChartNumericData(List.of(12.0, 15.0, 21.0, 24.0, 30.0, 33.0)));
            chart.getSeries().add(series);

            // Display circle markers without lines.
            Marker marker = new Marker();
            marker.setSymbol(MarkerStyle.CIRCLE);
            marker.setSize(9);
            series.setMarker(marker);
            OutlineStyle noLine = new OutlineStyle();
            noLine.setFill(new NoFill());
            ChartElement seriesProperties = new ChartElement();
            seriesProperties.setOutlineStyle(noLine);
            series.setProperties(seriesProperties);

            // Add a linear trend line.
            TrendLine trendLine = new TrendLine();
            trendLine.setType(TrendLineType.LINEAR);
            series.setTrendLine(trendLine);

            // Display values above data points.
            ScatterChartView view = (ScatterChartView) chart.getViews().get(0);
            view.getDataLabels().setShowValue(true);
            view.getDataLabels().setLabelPosition(ScatterDataLabelPosition.TOP);

            // 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:

 Scatter chart with markers, a linear trend line, and data labels created with the DevExpress Presentation API for Java

Add BubbleSeries objects to a chart to create a bubble chart. A bubble series also displays bubble sizes. Call the following methods to configure bubbles:

Method Description
setBubbleSize(IChartValueData value) Sets bubble size data.
setBubbleScale(int value) Sets the bubble scale as a percentage of the default bubble size.
setSizeRepresentation(BubbleSizeRepresentation value) Sets the bubble dimension that bubble size values determine.
setShowNegativeBubbles(boolean value) Sets whether to display bubbles with negative size values.

The following code snippet creates a bubble chart, reduces the bubble size, and displays bubble sizes in data labels:

import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

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);

            // Create a bubble series: X values, Y values, and bubble sizes.
            BubbleSeries series = new BubbleSeries();
            series.setText("Products");
            series.setArguments(new ChartNumericData(List.of(10.0, 25.0, 40.0, 55.0)));
            series.setValues(new ChartNumericData(List.of(30.0, 55.0, 20.0, 70.0)));
            series.setBubbleSize(new ChartNumericData(List.of(120.0, 60.0, 200.0, 90.0)));
            chart.getSeries().add(series);

            // Reduce bubble size and display bubble sizes in data labels.
            BubbleChartView view = (BubbleChartView) chart.getViews().get(0);
            view.setBubbleScale(60);
            view.getDataLabels().setShowBubbleSize(true);
            view.getDataLabels().setLabelPosition(BubbleDataLabelPosition.CENTER);

            // 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:

 Bubble chart with bubble sizes in data labels created with the DevExpress Presentation API for Java

Radar Charts

Add RadarSeries objects to a chart to create a radar chart. Call the following methods to configure radar series and the chart view:

Method Description
RadarChartView.setStyle(value) Sets the radar chart style.
RadarSeries.setMarker(value) Sets marker settings for series data points.

The following code snippet creates a filled radar chart that compares two products and displays a data label for one data point:

import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

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);

            // Add a radar series for each product.
            String[] names = { "Product A", "Product B" };
            double[][] scores = { { 8, 6, 9, 5, 7 }, { 6, 9, 5, 8, 6 } };
            for (int i = 0; i < names.length; i++) {
                RadarSeries series = new RadarSeries();
                series.setText(names[i]);
                series.setArguments(new ChartStringData(List.of("Price", "Quality", "Design", "Support", "Delivery")));
                series.setValues(new ChartNumericData(List.of(scores[i][0], scores[i][1], scores[i][2], scores[i][3], scores[i][4])));
                chart.getSeries().add(series);
            }

            // Display series as filled areas.
            RadarChartView view = (RadarChartView) chart.getViews().get(0);
            view.setStyle(RadarChartStyle.FILLED);

            // Display the Design score of the first product.
            RadarDataLabel label = new RadarDataLabel();
            label.setShowValue(true);
            RadarSeries firstSeries = (RadarSeries) chart.getSeries().get(0);
            firstSeries.getDataLabels().setLabel(2, label);

            // 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:

 Filled radar chart that compares two products created with the DevExpress Presentation API for Java

Stock Charts

Add StockSeries objects to a chart to create a stock chart.

Note

Add Open, High, Low, and Close series to a stock chart in this order.

Call the following methods to configure the chart view:

Method Description
setShowHighLowLines(boolean value) Sets whether the view displays high-low lines.
setShowUpDownBars(boolean value) Sets whether the view displays up-down bars.
setUpBarProperties(ChartElement value) Sets fill and outline settings for up bars.
setDownBarProperties(ChartElement value) Sets fill and outline settings for down bars.
setShowDropLines(boolean value) Sets whether the view displays drop lines.

The following code snippet creates a stock chart with Open, High, Low, and Close series, displays high-low lines and colored up-down bars, and displays closing prices in data labels:

import java.io.*;
import java.nio.file.*;
import java.util.List;
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);

            // Add Open, High, Low, and Close series in this order.
            String[] names = { "Open", "High", "Low", "Close" };
            double[][] prices = {
                { 96, 88, 77, 92, 83 },
                { 100, 110, 105, 115, 99 },
                { 80, 73, 72, 78, 71 },
                { 90, 100, 81, 86, 88 }
            };
            for (int i = 0; i < names.length; i++) {
                StockSeries series = new StockSeries();
                series.setText(names[i]);
                series.setArguments(new ChartStringData(List.of("Mon", "Tue", "Wed", "Thu", "Fri")));
                series.setValues(new ChartNumericData(List.of(prices[i][0], prices[i][1], prices[i][2], prices[i][3], prices[i][4])));

                // Hide series lines and markers.
                OutlineStyle outline = new OutlineStyle();
                outline.setFill(new NoFill());
                ChartElement properties = new ChartElement();
                properties.setOutlineStyle(outline);
                series.setProperties(properties);
                Marker marker = new Marker();
                marker.setSymbol(MarkerStyle.NONE);
                series.setMarker(marker);
                chart.getSeries().add(series);
            }

            // Display high-low lines and up-down bars.
            StockChartView view = (StockChartView) chart.getViews().get(0);
            view.setShowHighLowLines(true);
            view.setShowUpDownBars(true);
            ChartElement upBars = new ChartElement();
            upBars.setFill(new SolidFill(Color.getSeaGreen()));
            view.setUpBarProperties(upBars);
            ChartElement downBars = new ChartElement();
            downBars.setFill(new SolidFill(Color.getIndianRed()));
            view.setDownBarProperties(downBars);

            // Display closing prices to the right of data points.
            StockSeries closeSeries = (StockSeries) chart.getSeries().get(3);
            closeSeries.getDataLabels().setShowValue(true);
            closeSeries.getDataLabels().setLabelPosition(StockDataLabelPosition.RIGHT);

            // Save the presentation.
            Files.createDirectories(Path.of("output"));
            try (OutputStream output = Files.newOutputStream(Path.of("output", "Chart.pptx"))) {
                presentation.save(output);
            }
        }
    }
}

Surface Charts

Add SurfaceSeries objects to a chart to create a surface chart. Call the SurfaceChartView.setDisplayAsWireframe(value) method to display the surface as a wireframe.

The following code snippet creates a surface chart with four series and displays the surface as a wireframe:

import java.io.*;
import java.nio.file.*;
import java.util.List;
import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

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);

            // Add a surface series for each data row.
            String[] names = { "Row 1", "Row 2", "Row 3", "Row 4" };
            double[][] values = {
                { 10, 25, 30, 20, 15 },
                { 20, 40, 55, 35, 25 },
                { 15, 35, 45, 40, 20 },
                { 5, 15, 25, 20, 10 }
            };
            for (int i = 0; i < names.length; i++) {
                SurfaceSeries series = new SurfaceSeries();
                series.setText(names[i]);
                series.setArguments(new ChartStringData(List.of("A", "B", "C", "D", "E")));
                series.setValues(new ChartNumericData(List.of(values[i][0], values[i][1], values[i][2], values[i][3], values[i][4])));
                chart.getSeries().add(series);
            }

            // Display the surface as a wireframe.
            SurfaceChartView view = (SurfaceChartView) chart.getViews().get(0);
            view.setDisplayAsWireframe(true);

            // Save the presentation.
            Files.createDirectories(Path.of("output"));
            try (OutputStream output = Files.newOutputStream(Path.of("output", "Chart.pptx"))) {
                presentation.save(output);
            }
        }
    }
}

3D Charts

To create a 3D chart, add Area3DSeries, Bar3DSeries, Line3DSeries, Pie3DSeries, or Surface3DSeries objects to a chart.

To specify 3D view settings, pass a View3DOptions object to the Chart.setView3D(value) method. Call the following methods to configure the 3D view:

Method Description
setXRotation(int value) Sets the rotation of a 3D chart around the x-axis.
setYRotation(int value) Sets the rotation of a 3D chart around the y-axis.
setPerspective(int value) Sets the perspective angle of a 3D chart.
setRightAngleAxes(boolean value) Sets whether a 3D chart uses right-angle axes.
setDepthPercent(float value) Sets the depth of a 3D chart as a percentage factor.
setFloor(SurfaceOptions value) Sets settings for the floor of a 3D chart.
setBackWall(SurfaceOptions value) Sets settings for the back wall of a 3D chart.
setSideWall(SurfaceOptions value) Sets settings for the side wall of a 3D chart.

The following code snippet creates a 3D bar chart, specifies rotation, perspective, and depth, and fills the chart floor and back wall:

import java.io.*;
import java.nio.file.*;
import java.util.List;
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);

            // Add a 3D bar series.
            Bar3DSeries series = new Bar3DSeries();
            series.setArguments(new ChartStringData(List.of("Q1", "Q2", "Q3", "Q4")));
            series.setValues(new ChartNumericData(List.of(12.0, 18.0, 15.0, 21.0)));
            chart.getSeries().add(series);

            // Rotate the chart and specify perspective and depth.
            View3DOptions view3D = new View3DOptions();
            view3D.setXRotation(20);
            view3D.setYRotation(40);
            view3D.setPerspective(60);
            view3D.setDepthPercent(2f);

            // Fill the floor and back wall.
            SurfaceOptions floor = new SurfaceOptions();
            floor.setFill(new SolidFill(Color.getLightGray()));
            view3D.setFloor(floor);
            SurfaceOptions backWall = new SurfaceOptions();
            backWall.setFill(new SolidFill(Color.getAliceBlue()));
            view3D.setBackWall(backWall);
            chart.setView3D(view3D);

            // 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:

 3D column chart with rotation, perspective, and a filled floor and back wall created with the DevExpress Presentation API for Java

Convert a Series to Another Chart Type

Call the SeriesBase.convertTo(chartType) method to create a series of another chart type with the same data and settings. To display the converted series, replace the source series in the Chart.getSeries() collection.

The following code snippet converts the first series of a chart to a line series:

SeriesBase lineSeries = chart.getSeries().get(0).convertTo(ChartType.LINE);
chart.getSeries().set(0, lineSeries);

Next Steps