Back to Devexpress

ChartText.SetReference(CellRange) Method

officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-charttext-dot-setreference-x28-devexpress-dot-spreadsheet-dot-cellrange-x29.md

latest6.8 KB
Original Source

ChartText.SetReference(CellRange) Method

Specifies the cell that is the source for the text used in a chart element.

Namespace : DevExpress.Spreadsheet.Charts

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void SetReference(
    CellRange range
)
vb
Sub SetReference(
    range As CellRange
)

Parameters

NameTypeDescription
rangeCellRange

A CellRange object that is the cell(s) containing text.

|

Example

The example below demonstrates how to add data series to a chart and change the cell range containing data for a specific series.

The code uses the SeriesCollection.Add method to create a series and add it to the ChartObject.Series collection. To specify series values contained in the worksheet range, create a ChartData object using the ChartData.FromRange method and assign it to the Series.Values property.

The ChartText.SetReference method is used to link the Series.SeriesName to the content of the worksheet cell.

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.ColumnClustered);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];
// Add series using a worksheet range as the data source.
chart.Series.Add(worksheet["D2"], worksheet["B3:B6"], worksheet["D3:D6"]);
chart.Series.Add(worksheet["F2"], worksheet["B3:B6"], worksheet["F3:F6"]);

// Change the data range for the series values.
chart.Series[1].Values = ChartData.FromRange(worksheet["E3:E6"]);

// Specify the cell that is the source for the series name.
chart.Series[1].SeriesName.SetReference(worksheet["E2"]);
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.ColumnClustered)
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")
' Add series using a worksheet range as the data source.
chart.Series.Add(worksheet("D2"), worksheet("B3:B6"), worksheet("D3:D6"))
chart.Series.Add(worksheet("F2"), worksheet("B3:B6"), worksheet("F3:F6"))

' Change the data range for the series values.
chart.Series(1).Values = ChartData.FromRange(worksheet("E3:E6"))

' Specify the cell that is the source for the series name.
chart.Series(1).SeriesName.SetReference(worksheet("E2"))

The following code snippets (auto-collected from DevExpress Examples) contain references to the SetReference(CellRange) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-spreadsheet-chart-api/CS/SpreadsheetWPFChartAPISamples/CodeExamples/ChartSheetActions.cs#L53

csharp
chart.Title.Visible = true;
chart.Title.SetReference(worksheet["B1"]);

winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/CodeExamples/ChartSheetActions.cs#L53

csharp
chart.Title.Visible = true;
chart.Title.SetReference(worksheet["B1"]);

spreadsheet-document-api-chart-examples/CS/SpreadsheetDocServerChartAPISamples/CodeExamples/ChartActions.cs#L68

csharp
chart.Title.Visible = true;
chart.Title.SetReference(worksheet["B1"]);

wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/CodeExamples/ChartSheetActions.vb#L52

vb
chart.Title.Visible = True
chart.Title.SetReference(worksheet("B1"))

winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/CodeExamples/ChartSheetActions.vb#L51

vb
chart.Title.Visible = True
chart.Title.SetReference(worksheet("B1"))

spreadsheet-document-api-chart-examples/VB/SpreadsheetDocServerChartAPISamples/CodeExamples/ChartActions.vb#L67

vb
chart.Title.Visible = True
chart.Title.SetReference(worksheet("B1"))

See Also

ChartText Interface

ChartText Members

DevExpress.Spreadsheet.Charts Namespace