Back to Devexpress

How to: Move a Chart to a Chart Sheet

officefileapi-120716-spreadsheet-document-api-examples-charts-how-to-move-a-chart-to-a-chart-sheet.md

latest1.4 KB
Original Source

How to: Move a Chart to a Chart Sheet

  • Sep 19, 2023

The following example demonstrates how to move an existing chart from a worksheet to a separate chart sheet. To do this, call the ChartObject.MoveToNewChartSheet method for a chart you wish to move.

To transfer a chart back to the worksheet containing the source data, use the ChartObject.MoveToWorksheet method.

csharp
// Create an embedded chart on the worksheet.
Chart chart = worksheet.Charts.Add(ChartType.Pie, worksheet["B2:C7"]);
chart.TopLeftCell = worksheet.Cells["E2"];
chart.BottomRightCell = worksheet.Cells["K15"];

// Move the chart to a chart sheet.
ChartSheet chartSheet = chart.MoveToNewChartSheet("Chart");
vb
' Create an embedded chart on the worksheet.
Dim chart As Chart = worksheet.Charts.Add(ChartType.Pie, worksheet("B2:C7"))
chart.TopLeftCell = worksheet.Cells("E2")
chart.BottomRightCell = worksheet.Cells("K15")

' Move the chart to a chart sheet.
Dim chartSheet As ChartSheet = chart.MoveToNewChartSheet("Chart")