Interface IChartSeries
Represents the collection of chart series.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Base.dll
Syntax
public interface IChartSeries : IParentApplication, ICollection<IChartSerie>, IEnumerable<IChartSerie>, IEnumerable
Properties
Count
Returns the number of IChartSerie in the IChartSeries collection. Read-only Long.
Declaration
int Count { get; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to get the number of IChartSerie in the IChartSeries collection.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Check count
Console.Write(chart.Series.Count);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//1
Item[Int32]
Returns a single IChartSerie object from IChartSeries collection.
Declaration
IChartSerie this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Property Value
Type |
---|
IChartSerie |
Examples
The following code illustrates how access a IChartSerie in the IChartSeries collection.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart type
chart.ChartType = ExcelChartType.WaterFall;
//Set serie format
IChartSerieDataFormat format = chart.Series[0].SerieFormat;
//Set visibility
format.ShowConnectorLines = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Item[String]
Returns a single IChartSerie object from IChartSeries collection.
Declaration
IChartSerie this[string name] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.String | name |
Property Value
Type |
---|
IChartSerie |
Examples
The following code illustrates how access a IChartSerie in the IChartSeries collection.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set serie
IChartSerie serie = chart.Series.Add("BarSerie", ExcelChartType.Bar_Clustered);
//Set category labels and values
chart.Series["BarSerie"].CategoryLabels = sheet.Range["A1:C1"];
chart.Series["BarSerie"].Values = sheet.Range["A2:C2"];
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Methods
Add()
Adds a new IChartSerie to IChartSeries collection and Returns it.
Declaration
IChartSerie Add()
Returns
Type | Description |
---|---|
IChartSerie | Newly created IChartSerie object. |
Examples
The following code illustrates how a IChartSerie can be created and added to IChartSeries collection.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set serie
IChartSerie serie = chart.Series.Add();
//Set category labels and values
serie.CategoryLabels = sheet.Range["A1:C1"];
serie.Values = sheet.Range["A2:C2"];
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Add(ExcelChartType)
Adds a new IChartSerie to IChartSeries collection and Returns it.
Declaration
IChartSerie Add(ExcelChartType serieType)
Parameters
Type | Name | Description |
---|---|---|
ExcelChartType | serieType | Type of new IChartSerie. |
Returns
Type | Description |
---|---|
IChartSerie | Newly created IChartSerie object. |
Examples
The following code illustrates how a IChartSerie can be created and added to IChartSeries collection by passing ExcelChartType as a parameter.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set serie
IChartSerie serie = chart.Series.Add(ExcelChartType.Bar_Clustered);
//Set category labels and values
serie.CategoryLabels = sheet.Range["A1:C1"];
serie.Values = sheet.Range["A2:C2"];
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Add(String)
Adds a new IChartSerie to IChartSeries collection and Returns it.
Declaration
IChartSerie Add(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the new IChartSerie. |
Returns
Type | Description |
---|---|
IChartSerie | Newly created IChartSerie object. |
Examples
The following code illustrates how a IChartSerie can be created and added to IChartSeries collection by passing System.String type as a parameter.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set serie
IChartSerie serie = chart.Series.Add("BarSerie");
//Set category labels and values
serie.CategoryLabels = sheet.Range["A1:C1"];
serie.Values = sheet.Range["A2:C2"];
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Add(String, ExcelChartType)
Adds a new IChartSerie to IChartSeries collection and Returns it.
Declaration
IChartSerie Add(string name, ExcelChartType type)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the new IChartSerie. |
ExcelChartType | type | Type of new IChartSerie. |
Returns
Type | Description |
---|---|
IChartSerie | Newly created IChartSerie. |
Examples
The following code illustrates how a IChartSerie can be created and added to IChartSeries collection by passing ExcelChartType and System.String type as parameters.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set serie
IChartSerie serie = chart.Series.Add("BarSerie", ExcelChartType.Bar_Clustered);
//Set category labels and values
chart.Series["BarSerie"].CategoryLabels = sheet.Range["A1:C1"];
chart.Series["BarSerie"].Values = sheet.Range["A2:C2"];
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Remove(String)
Removes a IChartSerie from IChartSeries collection.
Declaration
void Remove(string serieName)
Parameters
Type | Name | Description |
---|---|---|
System.String | serieName | IChartSerie name to remove. |
Examples
The following code illustrates how to remove a IChartSerie from IChartSeries collection by specfiying it's name.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set serie
IChartSerie serie = chart.Series.Add("BarSerie");
//Set category labels and values
serie.CategoryLabels = sheet.Range["A1:C1"];
serie.Values = sheet.Range["A2:C2"];
//Remove Serie
chart.Series.Remove("BarSerie");
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
RemoveAt(Int32)
Removes a IChartSerie from IChartSeries collection.
Declaration
void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Index of the IChartSerie to remove. |
Examples
The following code illustrates how to remove a IChartSerie from IChartSeries collection by specfiying it's index.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set serie
IChartSerie serie = chart.Series.Add("BarSerie");
//Set category labels and values
serie.CategoryLabels = sheet.Range["A1:C1"];
serie.Values = sheet.Range["A2:C2"];
//Remove Serie
chart.Series.RemoveAt(0);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}