Other API Samples

Live SpreadsheetGear API Samples

Charting Create Chart Sheet

Creates a ChartSheet and populates it with some series data.

// Create a new workbook and some local variables.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IWorksheet worksheet = workbook.ActiveWorksheet;
SpreadsheetGear.IRange cells = worksheet.Cells;

// Setup some sample data to create a chart series.
cells["A1:D8"].Formula = "=RANDBETWEEN(1, 100)";

// Add a ChartSheet to the workbook and set its name
SpreadsheetGear.IChartSheet chartSheet = workbook.ChartSheets.Add();
chartSheet.Name = "My Chart Sheet";

// Get a reference to the IChart on the ChartSheet.
SpreadsheetGear.Charts.IChart chart = chartSheet.Chart;

// Populate the chart with some data.
chart.SetSourceData(cells["A1:D8"], SpreadsheetGear.Charts.RowCol.Columns);

// Set the ChartType.
chart.ChartType = SpreadsheetGear.Charts.ChartType.BarClustered;
Run This Sample
Download File

Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.