Documents for Excel .NET Edition | GCDocuments
Features / Chart / Customize Chart Objects / Series
In This Topic
    Series
    In This Topic

    Series refers to a set of data points, or simply a list of values that are plotted in a chart.

    In a spreadsheet, you can plot one or more data series while creating a chart. Each series is represented by an item on the legend and provides access to the chart control's collection of series objects.

    In GcExcel .NET, the SeriesCollection can be used to create chart series. The properties and methods of the ISeries interface and the ISeriesCollection interface allows users to add individual series, access it, delete it and perform other useful operations on it as per the requirements.

    Refer to the following example code to add series in your chart.

    C#
    Copy Code
       // Adding charts
    IShape shape1 = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 50, 300, 300);
    worksheet.Range["A1:D6"].Value = new object[,]
     {
       {null, "S1", "S2", "S3"},
       {"Item1", 10, 25, 25},
       {"Item2", 51, 36, 27},
       {"Item3", 52, 85, 30},
       {"Item4", 22, 65, 65},
       {"Item5", 23, 69, 69}
    };
    
       //Detects three series, B2:B6, C2:C6, D2:D6.
       //Does not detect out series labels and category labels, auto generated.
       shape1.Chart.SeriesCollection.Add(worksheet.Range["B2:D6"]);
    
       IShape shape2 = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 550, 50, 300, 300);
       //Detects three series, B2:B6, C2:C6, D2:D6.
       //Detects out series labels and category labels.
       //Series labels are "S1", "S2", "S3".
       //Category labels are "Item1", "Item2", "Item3", "Item4", "Item5".
       shape2.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"]);
    
       IShape shape3 = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 450, 300, 300);
       //Detects five series, B2:D2, B3:C3, B4:C4, B5:C5, B6:C6.
       //Does not detects out series labels and category labels, auto generated.
       shape3.Chart.SeriesCollection.Add(worksheet.Range["B2:D6"], RowCol.Rows);
    
       IShape shape4 = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 550, 450, 300, 300);
       //Detects three series, B2:B6, C2:C6, D2:D6
       //Does not detects out series labels and category labels, auto generated.
       shape4.Chart.SeriesCollection.Add(worksheet.Range["B2:D6"], RowCol.Columns);
    
       IShape shape5 = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 850, 450, 300, 300);
       //Detects three series, B2:B6, C2:C6, D2:D6
       //Detects out series labels and category labels.
       //Series labels are "S1", "S2", "S3".
       //Category labels are "Item1", "Item2", "Item3", "Item4", "Item5".
       shape5.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns);
    
       IShape shape6 = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 750, 300, 300);
       //Detects three series, B2:B6, C2:C6, D2:D6
       //Detects out series labels and category labels.
       //Series labels are "S1", "S2", "S3".
       //Category labels are "Item1", "Item2", "Item3", "Item4", "Item5".
       shape6.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], RowCol.Columns, true, true);
    
       workbook.Worksheets.Add();
       IWorksheet worksheet1 = workbook.Worksheets[1];
       worksheet1.Range["A1:D6"].Value = new object[,]
     {
       {null, "S1", "S2", "S3"},
       {"Item1", 10, 25, 25},
       {"Item2", -51, -36, 27},
       {"Item3", 52, -85, -30},
       {"Item4", 22, 65, 65},
       {"Item5", 23, 69, 69}
     };
    
       //Use ISeriesCollection.NewSeries() to add series
       IShape shape7 = worksheet1.Shapes.AddChart(ChartType.ColumnClustered, 200, 50, 300, 300);
       ISeries series1 = shape7.Chart.SeriesCollection.NewSeries();
       ISeries series2 = shape7.Chart.SeriesCollection.NewSeries();
       ISeries series3 = shape7.Chart.SeriesCollection.NewSeries();
       series1.Formula = "=SERIES(Sheet1!$B$1,Sheet1!$A$2:$A$6,Sheet1!$B$2:$B$6,1)";
       series2.Formula = "=SERIES(Sheet1!$C$1,Sheet1!$A$2:$A$6,Sheet1!$C$2:$C$6,2)";
       series3.Formula = "=SERIES(Sheet1!$D$1,Sheet1!$A$2:$A$6,Sheet1!$D$2:$D$6,3)";
    
       //Use ISeriesCollection.Extend(IRange source, RowCol rowcol, bool categoryLabels) to add new data points to existing series
       IShape shape8 = worksheet1.Shapes.AddChart(ChartType.ColumnClustered, 200, 450, 300, 300);
       shape8.Chart.SeriesCollection.Add(worksheet1.Range["A1:D6"], RowCol.Columns, true, true);
       worksheet1.Range["A12:D14"].Value = new object[,]
       {
           {"Item6", 50, 20, -30},
           {"Item7", 60, 50, 50},
           {"Item8", 35, 80, 60}
       };
       shape8.Chart.SeriesCollection.Extend(worksheet1.Range["A12:D14"], RowCol.Columns, true);
    
       workbook.Worksheets.Add();
       IWorksheet worksheet2 = workbook.Worksheets[2];
       worksheet2.Range["A1:D6"].Value = new object[,]
      {
           {null, "S1", "S2", "S3"},
           {"Item1", 10, 25, 25},
           {"Item2", -51, -36, 27},
           {"Item3", 52, -85, -30},
           {"Item4", 22, 65, 65},
           {"Item5", 23, 69, 69}
      };
    
       //Create a line chart, change one series's AxisGroup, change another one series's chart type.
       IShape shape9 = worksheet2.Shapes.AddChart(ChartType.Line, 200, 50, 300, 300);
       shape9.Chart.SeriesCollection.Add(worksheet2.Range["A1:D6"], RowCol.Columns, true, true);
       ISeries series4 = shape9.Chart.SeriesCollection[0];
       ISeries series5 = shape9.Chart.SeriesCollection[1];
       series4.AxisGroup = AxisGroup.Secondary;
       series5.ChartType = ChartType.ColumnClustered;
    
       //Set 3D column chart's bar shape.
       IShape shape10 = worksheet2.Shapes.AddChart(ChartType.Column3D, 200, 450, 300, 300);
       shape10.Chart.SeriesCollection.Add(worksheet2.Range["A1:D6"], RowCol.Columns, true, true);
       ISeries series6 = shape10.Chart.SeriesCollection[0];
       ISeries series7 = shape10.Chart.SeriesCollection[1];
       ISeries series8 = shape10.Chart.SeriesCollection[2];
       series6.BarShape = BarShape.ConeToMax;
       series7.BarShape = BarShape.Cylinder;
       series8.BarShape = BarShape.PyramidToPoint;
    
       //Set negative point's fill color.
       IShape shape11 = worksheet2.Shapes.AddChart(ChartType.Column3D, 200, 800, 300, 300);
       shape11.Chart.SeriesCollection.Add(worksheet2.Range["A1:D6"], RowCol.Columns, true, true);
       ISeries series9 = shape11.Chart.SeriesCollection[0];
       series9.InvertIfNegative = true;
       //Iussue to be escalated
       series9.InvertColor.RGB = Color.DarkOrange;
    
       //Set series' plot order.6
       IShape shape12 = worksheet2.Shapes.AddChart(ChartType.ColumnClustered, 200, 1100, 300, 300);
       worksheet.Range["A1:E6"].Value = new object[,]
       {
       {null, "S1", "S2", "S3", "S4"},
       {"Item1", 10, 25, 25, 30},
       {"Item2", -51, -36, 27, 35},
       {"Item3", 52, -85, -30, 40},
       {"Item4", 22, 65, 65, 45},
       {"Item5", 23, 69, 69, 50}
       };
       shape12.Chart.SeriesCollection.Add(worksheet2.Range["A1:E6"], RowCol.Columns, true, true);
    
       ISeries series10 = shape12.Chart.SeriesCollection[0];
       ISeries series11 = shape12.Chart.SeriesCollection[1];
       ISeries series12 = shape12.Chart.SeriesCollection[2];
       ISeries series13 = shape12.Chart.SeriesCollection[3];
    
       //series11 and series13 plot on secondary axis.
       series11.AxisGroup = AxisGroup.Secondary;
       series13.AxisGroup = AxisGroup.Secondary;
    
       //series10 and series12 are in one chart group.
       series12.PlotOrder = 1;
       series10.PlotOrder = 2;
    
       //series4 and series2 are in one chart group.
       series13.PlotOrder = 1;
       series11.PlotOrder = 2;
    
       //Config series' marker.
       IShape shape13 = worksheet2.Shapes.AddChart(ChartType.Line, 200, 1450, 300, 300);
       shape13.Chart.SeriesCollection.Add(worksheet2.Range["A1:D6"], RowCol.Columns, true, true);
    
       ISeries series14 = shape13.Chart.SeriesCollection[0];
    
       series14.MarkerStyle = MarkerStyle.Diamond;
       series14.MarkerSize = 10;
       series14.MarkerFormat.Fill.Color.RGB = Color.Red;
       series14.MarkerFormat.Line.Style = LineStyle.ThickThin;
       series14.MarkerFormat.Line.Color.RGB = Color.Green;
       series14.MarkerFormat.Line.Weight = 3;