LayoutPosition Class
A position or size value for a chart element and the layout mode of this value.
Declaration
public final class LayoutPosition extends Struct<LayoutPosition> implements IEquatable<LayoutPosition>
Remarks
Pass LayoutPosition values to LayoutOptions methods (for example, LayoutOptions.setLeft(value)) to position or size a chart element manually.
A LayoutPosition value contains a value (getValue()) and a layout mode (getMode()). Values are fractions of the chart width or height (for example, 0.05 corresponds to 5%). The mode specifies whether a value is an offset, a size, or an edge position. Refer to the LayoutModeType enumeration description for additional information.
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);
}
}
}
}
Implements
Inherited Members
Inheritance
Constructors
LayoutPosition() Constructor
Initializes a new instance of the LayoutPosition class.
Declaration
public LayoutPosition()
Remarks
The new layout position uses the LayoutModeType.EDGE mode and the 0 value.
LayoutPosition(LayoutModeType mode, double value) Constructor
Initializes a new instance of the LayoutPosition class with the specified layout mode and value.
Declaration
public LayoutPosition(LayoutModeType mode, double value)
Parameters
| Name | Type | Description |
|---|---|---|
| mode | LayoutModeType | The layout mode. |
| value | double | The position or size value as a fraction of the chart width or height. |
Methods
equals(LayoutPosition value) Method
Returns whether the specified layout position equals this layout position.
Declaration
public boolean equals(LayoutPosition value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | LayoutPosition |
The layout position to compare. |
Returns
| Type | Description |
|---|---|
| boolean |
|
equals(Object obj) Method
Returns whether the specified object equals this layout position.
Declaration
public boolean equals(Object obj)
Parameters
| Name | Type | Description |
|---|---|---|
| obj | Object | The object to compare. |
Returns
| Type | Description |
|---|---|
| boolean |
|
getMode() Method
Returns the layout mode of the position or size value.
Declaration
public LayoutModeType getMode()
Returns
| Type | Description |
|---|---|
| LayoutModeType | The layout mode. |
getValue() Method
Returns the position or size value.
Declaration
public double getValue()
Returns
| Type | Description |
|---|---|
| double | The value as a fraction of the chart width or height. |
hashCode() Method
Returns the hash code of the layout position.
Declaration
public int hashCode()
Returns
| Type | Description |
|---|---|
| int | The hash code. |