Skip to main content

LayoutOptions Class

Contains position and size settings for a chart element.

Declaration

public class LayoutOptions extends OfficeObject

Remarks

Pass a LayoutOptions object to the Legend.setLayout(value) method to position the legend manually.

Each position and size setting is a LayoutPosition value that contains a value and a mode (LayoutModeType). Values are fractions of the chart size (for example, 0.05 corresponds to 5% of the chart width or height). If a setting is null, the chart calculates the setting automatically.

Example

Position a Legend and Hide a Legend Entry

The following code snippet places the chart legend in the top-left corner of the chart and hides the legend entry for the first series:

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 two bar series.
            String[] names = { "2024", "2025" };
            double[][] values = { { 12, 18, 15 }, { 14, 20, 19 } };
            for (int i = 0; i < names.length; i++) {
                BarSeries series = new BarSeries();
                series.setText(names[i]);
                series.setArguments(new ChartStringData(List.of("Q1", "Q2", "Q3")));
                series.setValues(new ChartNumericData(List.of(values[i][0], values[i][1], values[i][2])));
                chart.getSeries().add(series);
            }

            // Place the legend in the top-left corner of the chart.
            Legend legend = new Legend();
            LayoutOptions layout = new LayoutOptions();
            layout.setLeft(new LayoutPosition(LayoutModeType.EDGE, 0.05));
            layout.setTop(new LayoutPosition(LayoutModeType.EDGE, 0.05));
            layout.setWidth(new LayoutPosition(LayoutModeType.FACTOR, 0.15));
            layout.setHeight(new LayoutPosition(LayoutModeType.FACTOR, 0.15));
            legend.setLayout(layout);

            // Hide the legend entry for the first series.
            LegendEntry entry = new LegendEntry();
            entry.setHidden(true);
            legend.getCustomEntries().put(0, entry);
            chart.setLegend(legend);

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

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

Object
JavaObject
OfficeObject
LayoutOptions
See Also

LayoutOptions()

Initializes a new instance of the LayoutOptions class.

Declaration

public LayoutOptions()

Methods

deepClone() Method

Creates a copy of the layout settings.

Declaration

public LayoutOptions deepClone()

Returns

Type Description
LayoutOptions

A copy of the layout settings.

getHeight() Method

Returns the height or bottom edge position of the chart element.

Declaration

public @Nullable LayoutPosition getHeight()

Returns

Type Description
LayoutPosition

The height or bottom edge position, or null if the chart calculates the height automatically.

getLeft() Method

Returns the left position of the chart element.

Declaration

public @Nullable LayoutPosition getLeft()

Returns

Type Description
LayoutPosition

The left position, or null if the chart calculates the position automatically.

getTarget() Method

Returns the area of the chart element to which layout settings apply.

Declaration

public LayoutTargetType getTarget()

Returns

Type Description
LayoutTargetType

The layout target.

getTop() Method

Returns the top position of the chart element.

Declaration

public @Nullable LayoutPosition getTop()

Returns

Type Description
LayoutPosition

The top position, or null if the chart calculates the position automatically.

getWidth() Method

Returns the width or right edge position of the chart element.

Declaration

public @Nullable LayoutPosition getWidth()

Returns

Type Description
LayoutPosition

The width or right edge position, or null if the chart calculates the width automatically.

setHeight(@Nullable LayoutPosition value) Method

Sets the height or bottom edge position of the chart element.

Declaration

public void setHeight(@Nullable LayoutPosition value)

Parameters

Name Type Description
value LayoutPosition

The height or bottom edge position, or null to calculate the height automatically.

Remarks

If the LayoutPosition.getMode() method returns LayoutModeType.FACTOR, the value specifies the height of the chart element. If the mode is LayoutModeType.EDGE, the value specifies the bottom edge position.

setLeft(@Nullable LayoutPosition value) Method

Sets the left position of the chart element.

Declaration

public void setLeft(@Nullable LayoutPosition value)

Parameters

Name Type Description
value LayoutPosition

The left position, or null to calculate the position automatically.

setTarget(LayoutTargetType value) Method

Sets the area of the chart element to which layout settings apply.

Declaration

public void setTarget(LayoutTargetType value)

Parameters

Name Type Description
value LayoutTargetType

The layout target.

Remarks

A new LayoutOptions object uses the LayoutTargetType.OUTER target.

The value parameter accepts the following values:

Value Description
INNER Layout settings apply to the plot area without tick marks and axis labels.
OUTER Layout settings apply to the plot area with tick marks and axis labels.

setTop(@Nullable LayoutPosition value) Method

Sets the top position of the chart element.

Declaration

public void setTop(@Nullable LayoutPosition value)

Parameters

Name Type Description
value LayoutPosition

The top position, or null to calculate the position automatically.

setWidth(@Nullable LayoutPosition value) Method

Sets the width or right edge position of the chart element.

Declaration

public void setWidth(@Nullable LayoutPosition value)

Parameters

Name Type Description
value LayoutPosition

The width or right edge position, or null to calculate the width automatically.

Remarks

If the LayoutPosition.getMode() method returns LayoutModeType.FACTOR, the value specifies the width of the chart element. If the mode is LayoutModeType.EDGE, the value specifies the right edge position.