Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

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

...