officefileapi-devexpress-dot-spreadsheet-dot-chartsheetcollection-dot-add-x28-devexpress-dot-spreadsheet-dot-charts-dot-charttype-x29.md
Creates a new chart sheet of the specified type and appends it to the end of the collection.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
ChartSheet Add(
ChartType chartType
)
Function Add(
chartType As ChartType
) As ChartSheet
| Name | Type | Description |
|---|---|---|
| chartType | ChartType |
A ChartType enumeration member specifying the chart type.
|
| Type | Description |
|---|---|
| ChartSheet |
A ChartSheet object that specifies the new chart sheet.
|
The Add method creates a new chart sheet under the default name like ChartN, where N is a number that is greater by 1 than the maximum number used in chart sheet names of the same type. To change the chart sheet name, use the ChartSheet.Name property. Use the ChartSheet.Chart property to access a chart located on the chart sheet and specify its settings (select chart data and adjust the chart appearance).
To insert a new chart sheet to the specified position in the collection, use the ChartSheetCollection.Insert method.
To remove a chart sheet from the collection, use the ChartSheetCollection.Remove or ChartSheetCollection.RemoveAt method.
Worksheet worksheet = workbook.Worksheets["chartTask2"];
// Create an empty chart sheet of the specified type.
ChartSheet chartSheet = workbook.ChartSheets.Add(ChartType.BarFullStacked);
// Access a chart on the chart sheet.
ChartObject chart = chartSheet.Chart;
// Select chart data.
chart.SelectData(worksheet["B3:C8"], ChartDataDirection.Row);
// Display the chart title.
chart.Title.Visible = true;
chart.Title.SetReference(worksheet["B1"]);
// Change the legend position.
chart.Legend.Position = LegendPosition.Bottom;
// Hide the category axis.
chart.PrimaryAxes[0].Visible = false;
// Set the value axis' major unit.
chart.PrimaryAxes[1].MajorUnit = 0.2;
workbook.ChartSheets.ActiveChartSheet = chartSheet;
Dim worksheet As Worksheet = workbook.Worksheets("chartTask2")
' Create an empty chart sheet of the specified type.
Dim chartSheet As ChartSheet = workbook.ChartSheets.Add(ChartType.BarFullStacked)
' Access a chart on the chart sheet.
Dim chart As ChartObject = chartSheet.Chart
' Select chart data.
chart.SelectData(worksheet("B3:C8"), ChartDataDirection.Row)
' Display the chart title.
chart.Title.Visible = True
chart.Title.SetReference(worksheet("B1"))
' Change the legend position.
chart.Legend.Position = LegendPosition.Bottom
' Hide the category axis.
chart.PrimaryAxes(0).Visible = False
' Set the value axis' major unit.
chart.PrimaryAxes(1).MajorUnit = 0.2
workbook.ChartSheets.ActiveChartSheet = chartSheet
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/ChartSheetActions.cs#L44
// Create an empty chart sheet of the specified type.
ChartSheet chartSheet = workbook.ChartSheets.Add(ChartType.BarFullStacked);
winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/CodeExamples/ChartSheetActions.cs#L44
// Create an empty chart sheet of the specified type.
ChartSheet chartSheet = workbook.ChartSheets.Add(ChartType.BarFullStacked);
wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/CodeExamples/ChartSheetActions.vb#L43
' Create an empty chart sheet of the specified type.
Dim chartSheet As ChartSheet = workbook.ChartSheets.Add(ChartType.BarFullStacked)
winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/CodeExamples/ChartSheetActions.vb#L42
' Create an empty chart sheet of the specified type.
Dim chartSheet As ChartSheet = workbook.ChartSheets.Add(ChartType.BarFullStacked)
See Also