Back to Devexpress

ChartCollection.Add(ChartType) Method

officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-chartcollection-dot-add-x28-devexpress-dot-spreadsheet-dot-charts-dot-charttype-x29.md

latest6.4 KB
Original Source

ChartCollection.Add(ChartType) Method

Creates a chart of the specified type and adds it to the collection.

Namespace : DevExpress.Spreadsheet.Charts

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Chart Add(
    ChartType chartType
)
vb
Function Add(
    chartType As ChartType
) As Chart

Parameters

NameTypeDescription
chartTypeChartType

A ChartType enumeration member specifying the chart type.

|

Returns

TypeDescription
Chart

A Chart object that is the chart embedded in a worksheet.

|

Remarks

This example demonstrates how to create a chart using the ChartCollection.Add method and specify its data using the ChartObject.SelectData method.

The chart looks as follows.

View Example

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

// Create a chart and specify its location.
Chart chartRowData = worksheet.Charts.Add(ChartType.ColumnStacked);
chartRowData.TopLeftCell = worksheet.Cells["E3"];
chartRowData.BottomRightCell = worksheet.Cells["J12"];

// Select chart data.
chartRowData.SelectData(worksheet["B3:C8"]);
vb
Dim worksheet As Worksheet = workbook.Worksheets("chartTask2")
workbook.Worksheets.ActiveWorksheet = worksheet

' Create a chart and specify its location.
Dim chartRowData As Chart = worksheet.Charts.Add(ChartType.ColumnStacked)
chartRowData.TopLeftCell = worksheet.Cells("E3")
chartRowData.BottomRightCell = worksheet.Cells("J12")

' Select chart data.
chartRowData.SelectData(worksheet("B3:C8"))

The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(ChartType) 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/TrendlineActions.cs#L22

csharp
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnStacked);
chart.SelectData(worksheet["C2:F3"], ChartDataDirection.Row);

winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/CodeExamples/TrendlineActions.cs#L22

csharp
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnStacked);
chart.SelectData(worksheet["C2:F3"], ChartDataDirection.Row);

spreadsheet-document-api-chart-examples/CS/SpreadsheetDocServerChartAPISamples/CodeExamples/TrendlineActions.cs#L22

csharp
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnStacked);
chart.SelectData(worksheet["C2:F3"], ChartDataDirection.Row);

wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/CodeExamples/TrendlineActions.vb#L20

vb
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnStacked)
chart.SelectData(worksheet("C2:F3"), ChartDataDirection.Row)

winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/CodeExamples/TrendlineActions.vb#L19

vb
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnStacked)
chart.SelectData(worksheet("C2:F3"), ChartDataDirection.Row)

spreadsheet-document-api-chart-examples/VB/SpreadsheetDocServerChartAPISamples/CodeExamples/TrendlineActions.vb#L25

vb
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnStacked)
chart.SelectData(worksheet("C2:F3"), ChartDataDirection.Row)

See Also

ChartCollection Interface

ChartCollection Members

DevExpress.Spreadsheet.Charts Namespace