.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

ChartObject.ChangeType(ChartType) Method

Changes the type of the chart.

Namespace: DevExpress.Spreadsheet.Charts

Assembly: DevExpress.Spreadsheet.v21.1.Core.dll


void ChangeType(
    ChartType chartType


Name Type Description
chartType ChartType

A ChartType enumeration member that specifies the chart type.


The ChangeType method attempts to create a new chart of the specified type, apply settings obtained from the existing chart and substitute the current chart with a new one. If the method fails, an exception is thrown.

The example below demonstrates how to create a chart of the ChartType.PieExploded type. After that, the code attempts to change the chart type to ChartType.LineMarker using the ChartObject.ChangeType method. If you try to change the chart type to ChartType.StockHighLowClose (this line is commented), an exception will be thrown, because the data range is insufficient for this chart type, and the chart will be changed to ChartType.ColumnClustered.

Dim worksheet As Worksheet = workbook.Worksheets("chartTask1")
workbook.Worksheets.ActiveWorksheet = worksheet
' If a new chart type cannot be created with existing data, an exception is thrown.
'ChartType type1 = ChartType.StockHighLowClose;
Dim type1 As ChartType = ChartType.LineMarker
Dim type2 As ChartType = ChartType.ColumnClustered

' Create a chart and specify its location
Dim chart As Chart = worksheet.Charts.Add(ChartType.PieExploded, worksheet("B2:C7"))
chart.TopLeftCell = worksheet.Cells("E2")
chart.BottomRightCell = worksheet.Cells("K15")

' Hide the legend.
chart.Legend.Visible = False

' Change the chart type. 
Catch e As Exception
    MessageBox.Show(e.Message, "Incompatible chart type")
End Try
See Also