Interface IChartTrendLines
Interface that represents trend line collection.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.UWP.dll
Syntax
public interface IChartTrendLines
Properties
Count
Returns the number of IChartTrendLine in the IChartTrendLines collection. Read-only
Declaration
int Count { get; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to get the number of IChartTrendLine in the IChartTrendLines 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";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "25";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart serie
IChartSerie serie = chart.Series[0];
//Get chart serie trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendlines
IChartTrendLine trendLine1 = trendLines.Add(ExcelTrendLineType.Logarithmic);
IChartTrendLine trendLine2 = trendLines.Add(ExcelTrendLineType.Linear);
Console.WriteLine("Number of TrendLines created is: " + trendLines.Count);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//Number of TrendLines created is: 2
Item[Int32]
Gets single trend line by index. Read-only.
Declaration
IChartTrendLine this[int iIndex] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | iIndex |
Property Value
Type |
---|
IChartTrendLine |
Examples
The following code illustrates how to access IChartTrendLine from the IChartTrendLines 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";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "25";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart serie
IChartSerie serie = chart.Series[0];
//Get chart serie trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendlines
trendLines.Add(ExcelTrendLineType.Logarithmic);
trendLines.Add(ExcelTrendLineType.Linear);
//Accessing the first trendline from collection
IChartTrendLine trendline = trendLines[0];
//Set trendline Name
trendline.Name = "TrendLine 1";
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Methods
Add()
Adds a new IChartTrendLine to IChartTrendLines collection and Returns it.
Declaration
IChartTrendLine Add()
Returns
Type | Description |
---|---|
IChartTrendLine | Returns added trend line object. |
Examples
The following code illustrates how to access and add new instance of IChartTrendLine to IChartTrendLines
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";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "25";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart serie
IChartSerie serie = chart.Series[0];
//Get chart serie trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add new trendline instance
IChartTrendLine trendLine = trendLines.Add();
//Set trendline name
trendLine.Name = "trendline";
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Add(ExcelTrendLineType)
Adds a new IChartTrendLine with specified ExcelTrendLineType to IChartTrendLines collection and Returns it.
Declaration
IChartTrendLine Add(ExcelTrendLineType type)
Parameters
Type | Name | Description |
---|---|---|
ExcelTrendLineType | type | Represents type of trend line. |
Returns
Type | Description |
---|---|
IChartTrendLine | Returns added trend line object. |
Examples
The following code illustrates how to access and add new instance of IChartTrendLine with specified ExcelTrendLineType to IChartTrendLines
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";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "25";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart serie
IChartSerie serie = chart.Series[0];
//Get chart serie trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add new trendline instance with logarithmic type
IChartTrendLine trendLine = trendLines.Add(ExcelTrendLineType.Logarithmic);
//Set trendline name
trendLine.Name = "trendline";
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Clear()
Clears current IChartTrendLines collection.
Declaration
void Clear()
Examples
The following code illustrates how to clear IChartTrendLines 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";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "25";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart serie
IChartSerie serie = chart.Series[0];
//Get chart serie trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendlines
IChartTrendLine trendLine1 = trendLines.Add(ExcelTrendLineType.Logarithmic);
IChartTrendLine trendLine2 = trendLines.Add(ExcelTrendLineType.Linear);
Console.WriteLine("Before TrendLines Count is: " + trendLines.Count);
//Clears the trendlines collection
trendLines.Clear();
Console.WriteLine("After TrendLines Count is: " + trendLines.Count);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//Before TrendLines Count is: 2
//After TrendLines Count is: 0
RemoveAt(Int32)
Removes a IChartTrendLine from IChartTrendLines collection.
Declaration
void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Index of the IChartTrendLine to remove. |
Examples
The following code illustrates how to remove IChartTrendLine by index from IChartTrendLines
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";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "25";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C3"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart serie
IChartSerie serie = chart.Series[0];
//Get chart serie trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendlines
IChartTrendLine trendLine1 = trendLines.Add(ExcelTrendLineType.Logarithmic);
IChartTrendLine trendLine2 = trendLines.Add(ExcelTrendLineType.Linear);
Console.WriteLine("Before TrendLines Count is: " + trendLines.Count);
//Remove the trendline from the collection
trendLines.RemoveAt(0);
Console.WriteLine("After TrendLines Count is: " + trendLines.Count);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//Before TrendLines Count is: 2
//After TrendLines Count is: 1