Back to Devexpress

TrendlineLabel Interface

officefileapi-devexpress-dot-spreadsheet-dot-charts-7d59e5fc.md

latest3.8 KB
Original Source

TrendlineLabel Interface

A label displayed on a trendline.

Namespace : DevExpress.Spreadsheet.Charts

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface TrendlineLabel :
    ShapeFormat,
    ShapeFormatBase,
    ShapeTextFormat
vb
Public Interface TrendlineLabel
    Inherits ShapeFormat,
             ShapeFormatBase,
             ShapeTextFormat

The following members return TrendlineLabel objects:

Remarks

To display a trendline label, you have to set the Trendline.DisplayEquation or the Trendline.DisplayRSquare property to true.

The TrendlineLabel object is exposed by the Trendline.Label property.

Example

The code snippet below formats and positions a trendline’s label.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ScatterMarkers);
chart.SelectData(worksheet["C2:F3"], ChartDataDirection.Row);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];

// Display a polynomial trendline.
chart.Series[0].Trendlines.Add(ChartTrendlineType.Polynomial);

// Customize the trendline.
Trendline tline = chart.Series[0].Trendlines[0];
tline.DisplayEquation = true;
tline.CustomName = "Trend";
tline.DisplayRSquare = true;
tline.Outline.SetSolidFill(Color.Red);

// Format the trend label.
TrendlineLabel tlabel = tline.Label;
tlabel.Font.Name = "Tahoma";
tlabel.Font.Italic = true;
tlabel.Fill.SetGradientFill(ShapeGradientType.Linear, Color.Orange, Color.White);
// Position the label in the right quarter of the chart area.
tlabel.Layout.Left.SetPosition(LayoutMode.Edge, 0.75);
vb
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet

' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ScatterMarkers)
chart.SelectData(worksheet("C2:F3"), ChartDataDirection.Row)
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")

' Display a polynomial trendline.
chart.Series(0).Trendlines.Add(ChartTrendlineType.Polynomial)

' Customize the trendline.
Dim tline As Trendline = chart.Series(0).Trendlines(0)
tline.DisplayEquation = True
tline.CustomName = "Trend"
tline.DisplayRSquare = True
tline.Outline.SetSolidFill(Color.Red)

' Format the trend label.
Dim tlabel As TrendlineLabel = tline.Label
tlabel.Font.Name = "Tahoma"
tlabel.Font.Italic = True
tlabel.Fill.SetGradientFill(ShapeGradientType.Linear, Color.Orange, Color.White)
' Position the label in the right quarter of the chart area.
tlabel.Layout.Left.SetPosition(LayoutMode.Edge, 0.75)

See Also

TrendlineLabel Members

DevExpress.Spreadsheet.Charts Namespace