...
- Get a Charts collection:
The Charts collection contains all charts in a specified worksheet.Code Block c# c# ExcelApplication xla = new ExcelApplication(); Workbook wb = xla.Create(); Worksheet ws = wb.Worksheets[0]; Charts chrts = ws.Charts;
# - Create an anchor in the worksheet:
An anchor represents the position of a floating object (e.g., a chart) within a worksheet. The chart's top left corner will be placed at the anchor.Code Block c# c# Anchor anch = ws.CreateAnchor(7, 4, 0, 50);
# - Create a blank chart of a specified type, at the anchor you created:
The ChartType class contains all available chart types (e.g., Column) and sub-types (e.g., Clustered).Code Block c# c# Chart chrt = chrts.CreateChart(ChartType.Column.Clustered, anch);
# - Return a SeriesCollection object representing the set of data series in the chart:
Code Block c# c# SeriesCollection sc = chrt.SeriesCollection;
- Set the range of category (x) axis values:
Code Block c# c# sc.CategoryData = "Sheet1!A3:C3";
- Add a data series to the chart:
The formula passed to CreateSeries represents cells that contain the source values for the new data series.Code Block c# c# Series s = sc.CreateSeries("Sheet1!A25:C25");
...