Skip to main content

ScatterDataLabel Class

Contains settings for a data label in a scatter chart.

Declaration

public class ScatterDataLabel extends DataLabel

Remarks

The ScatterDataLabel class inherits label content and formatting settings from DataLabel and DataLabelBase classes (for example, ScatterDataLabel.setShowValue(value) and ScatterDataLabel.setCustomText(value) methods).

The setLabelPosition(ScatterDataLabelPosition value) method specifies the label position relative to the data point.

To format the data label of an individual data point, pass a ScatterDataLabel object to the IScatterDataLabels.setLabel(key, value) method.

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

Example: Display a Data Label for an Individual Point in a Scatter Chart

The following code snippet creates a scatter chart and displays the X and Y values of the last data point to the left of the 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);

            // Create a scatter series: temperature (X) and ice cream sales (Y).
            ScatterSeries series = new ScatterSeries();
            series.setText("Sales");
            series.setArguments(new ChartNumericData(List.of(14.0, 16.0, 19.0, 22.0, 25.0, 28.0)));
            series.setValues(new ChartNumericData(List.of(215.0, 325.0, 410.0, 520.0, 610.0, 680.0)));
            chart.getSeries().add(series);

            // Display the X and Y values of the last data point to the left of the point.
            ScatterDataLabel label = new ScatterDataLabel();
            label.setShowCategoryName(true);
            label.setShowValue(true);
            label.setLabelPosition(ScatterDataLabelPosition.LEFT);
            series.getDataLabels().setLabel(5, label);

            // 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.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
See Also

ScatterDataLabel()

Initializes a new instance of the ScatterDataLabel class.

Declaration

public ScatterDataLabel()

Methods

deepClone() Method

Returns a deep copy of this ScatterDataLabel instance.

Declaration

public ScatterDataLabel deepClone()

Returns

Type Description
ScatterDataLabel

A deep copy of this ScatterDataLabel.

getLabelPosition() Method

Returns the data label position relative to the data point.

Declaration

public ScatterDataLabelPosition getLabelPosition()

Returns

Type Description
ScatterDataLabelPosition

The data label position.

setLabelPosition(ScatterDataLabelPosition value) Method

Sets the data label position relative to the data point.

Declaration

public void setLabelPosition(ScatterDataLabelPosition value)

Parameters

Name Type Description
value ScatterDataLabelPosition

The data label position.

Exceptions

Type Description
NullPointerException

Thrown if the value parameter is null.

Remarks

The setLabelPosition(value) method accepts the following values:

Value Description
LEFT Indicates that the data label is to the left of the data point.
TOP Indicates that the data label is above the data point.
RIGHT Indicates that the data label is to the right of the data point.
BOTTOM Indicates that the data label is below the data point.
CENTER Indicates that the data label is centered on the data point.
DEFAULT Indicates that the data label position is not specified, and the chart application uses the default position.

If you do not call the setLabelPosition(value) method, the API uses ScatterDataLabelPosition.DEFAULT for a new data label and the value from the document for a loaded data label.