officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-chartcollection-dot-add-x28-devexpress-dot-spreadsheet-dot-charts-dot-charttype-x29.md
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
Chart Add(
ChartType chartType
)
Function Add(
chartType As ChartType
) As Chart
| Name | Type | Description |
|---|---|---|
| chartType | ChartType |
A ChartType enumeration member specifying the chart type.
|
| Type | Description |
|---|---|
| Chart |
A Chart object that is the chart embedded in a worksheet.
|
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.
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"]);
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
// 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
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnStacked);
chart.SelectData(worksheet["C2:F3"], ChartDataDirection.Row);
// 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
' 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
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnStacked)
chart.SelectData(worksheet("C2:F3"), ChartDataDirection.Row)
' 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