TrendLineLabel Class
Contains settings for the label that displays the trend line equation and R-squared value.
Declaration
public class TrendLineLabel extends ChartElement
Remarks
The TrendLine.setEquationLabel(value) method applies label settings to a trend line. TrendLine.setShowEquationLabel(value) and TrendLine.setShowRSquaredValue(value) methods specify label content.
setCustomText(TextArea value) and setTextReference(IChartDataReference value) methods replace label content with custom text or text from a chart data reference.
Refer to the following help topic for additional information: Add Error Bars and Trend Lines to Charts — Presentation API for Java.
Example
Add a Linear Trend Line with an Equation Label to a Line Chart
The following code snippet adds a linear trend line to a line series, extends the trend line two periods forward, and displays the trend line equation and R-squared value in bold:
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 line series.
LineSeries series = new LineSeries();
series.setText("Sales");
series.setArguments(new ChartStringData(List.of("Jan", "Feb", "Mar", "Apr", "May", "Jun")));
series.setValues(new ChartNumericData(List.of(15.0, 18.0, 24.0, 21.0, 28.0, 31.0)));
chart.getSeries().add(series);
// Add a linear trend line that extends two periods forward.
TrendLine trendLine = new TrendLine();
trendLine.setName("Sales Trend");
trendLine.setType(TrendLineType.LINEAR);
trendLine.setForecastForward(2);
// Display the trend line equation and R-squared value in bold.
trendLine.setShowEquationLabel(true);
trendLine.setShowRSquaredValue(true);
TextProperties labelText = new TextProperties();
labelText.setFontSize(16f);
labelText.setBold(true);
TrendLineLabel label = new TrendLineLabel();
label.setTextProperties(labelText);
trendLine.setEquationLabel(label);
// Display the trend line as a dashed orange line.
OutlineStyle trendLineStyle = new OutlineStyle();
trendLineStyle.setFill(new SolidFill(Color.getOrange()));
trendLineStyle.setWidth(10);
trendLineStyle.setDashType(LineDashType.DASH);
trendLine.setOutlineStyle(trendLineStyle);
series.setTrendLine(trendLine);
// 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:

Inherited Members
Inheritance
TrendLineLabel()
Initializes a new instance of the TrendLineLabel class.
Declaration
public TrendLineLabel()
Methods
deepClone() Method
Returns a deep copy of this TrendLineLabel instance.
Declaration
public TrendLineLabel deepClone()
Returns
| Type | Description |
|---|---|
TrendLineLabel |
A deep copy of this |
getCustomText() Method
Returns custom text of the trend line label.
Declaration
public TextArea getCustomText()
Returns
| Type | Description |
|---|---|
| TextArea | Custom text of the trend line label. |
getLayout() Method
Returns layout settings of the trend line label.
Declaration
public LayoutOptions getLayout()
Returns
| Type | Description |
|---|---|
| LayoutOptions | Layout settings of the trend line label. |
getNumberFormat() Method
Returns number format settings for numbers in the trend line label.
Declaration
public NumberFormatOptions getNumberFormat()
Returns
| Type | Description |
|---|---|
| NumberFormatOptions | Number format settings for numbers in the trend line label. |
getTextProperties() Method
Returns text formatting settings of the trend line label.
Declaration
public TextProperties getTextProperties()
Returns
| Type | Description |
|---|---|
| TextProperties | Text formatting settings of the trend line label. |
getTextReference() Method
Returns a chart data reference to the trend line label text.
Declaration
public IChartDataReference getTextReference()
Returns
| Type | Description |
|---|---|
| IChartDataReference | A reference to the label text. |
setCustomText(TextArea value) Method
Sets custom text of the trend line label.
Declaration
public void setCustomText(TextArea value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | TextArea | Custom text of the trend line label. |
Remarks
If you pass a text area, the API clears the reference that the getTextReference() method returns.
For a new TrendLineLabel object, the getCustomText() method returns null.
setLayout(LayoutOptions value) Method
Sets layout settings of the trend line label.
Declaration
public void setLayout(LayoutOptions value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | LayoutOptions | Layout settings of the trend line label. |
Remarks
For a new TrendLineLabel object, the getLayout() method returns null.
setNumberFormat(NumberFormatOptions value) Method
Sets number format settings for numbers in the trend line label.
Declaration
public void setNumberFormat(NumberFormatOptions value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | NumberFormatOptions | Number format settings for numbers in the trend line label. |
Remarks
For a new TrendLineLabel object, the getNumberFormat() method returns null.
setTextProperties(TextProperties value) Method
Sets text formatting settings of the trend line label.
Declaration
public void setTextProperties(TextProperties value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | TextProperties | Text formatting settings of the trend line label. |
Remarks
For a new TrendLineLabel object, the getTextProperties() method returns null.
setTextReference(IChartDataReference value) Method
Sets a chart data reference to the trend line label text.
Declaration
public void setTextReference(IChartDataReference value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | IChartDataReference | A reference to the label text. |
Remarks
If you pass a reference, the API clears the custom text that the getCustomText() method returns.
For a new TrendLineLabel object, the getTextReference() method returns null.