officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-chartcollection-dot-add-x28-devexpress-dot-spreadsheet-dot-charts-dot-charttype-devexpress-dot-spreadsheet-dot-cellrange-x29.md
Creates a chart of the specified type with data from the specified range and adds the chart to the collection.
Namespace : DevExpress.Spreadsheet.Charts
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
Chart Add(
ChartType chartType,
CellRange range
)
Function Add(
chartType As ChartType,
range As CellRange
) As Chart
| Name | Type | Description |
|---|---|---|
| chartType | ChartType |
A ChartType enumeration member specifying the chart type.
| | range | CellRange |
A CellRange containing chart data.
|
| Type | Description |
|---|---|
| Chart |
A Chart object that is the chart embedded in a worksheet.
|
The example below demonstrates how to create a 3-D pie chart using the ChartCollection.Add method overload that allows you to specify a CellRange containing chart data.
Worksheet worksheet = workbook.Worksheets["chartTask1"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Create a pie chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.Pie3D, worksheet["B2:C7"]);
chart.TopLeftCell = worksheet.Cells["E2"];
chart.BottomRightCell = worksheet.Cells["K15"];
// Set the chart style.
chart.Style = ChartStyle.ColorGradient;
Dim worksheet As Worksheet = workbook.Worksheets("chartTask1")
workbook.Worksheets.ActiveWorksheet = worksheet
' Create a pie chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.Pie3D, worksheet("B2:C7"))
chart.TopLeftCell = worksheet.Cells("E2")
chart.BottomRightCell = worksheet.Cells("K15")
' Set the chart style.
chart.Style = ChartStyle.ColorGradient
The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(ChartType, 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.
winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/CodeExamples/DataTableActions.cs#L15
// Create a chart and specify its location
Chart chart = worksheet.Charts.Add(ChartType.Line, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
wpf-spreadsheet-chart-api/CS/SpreadsheetWPFChartAPISamples/CodeExamples/DataTableActions.cs#L15
// Create a chart and specify its location
Chart chart = worksheet.Charts.Add(ChartType.Line, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:D4"]);
chart.TopLeftCell = worksheet.Cells["H2"];
winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/CodeExamples/DataTableActions.vb#L12
'Create a chart and specify its location
Dim chart As Chart = worksheet.Charts.Add(ChartType.Line, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/CodeExamples/DataTableActions.vb#L14
' Create a chart and specify its location
Dim chart As Chart = worksheet.Charts.Add(ChartType.Line, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B2:F6"))
chart.TopLeftCell = worksheet.Cells("H2")
See Also