Interface IChartTrendLine
Represents ChartTrendLine interface.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Portable.dll
Syntax
public interface IChartTrendLine
Properties
Backward
Represents number of periods that the trend line extends backward.
Declaration
double Backward { get; set; }
Property Value
Type |
---|
System.Double |
Examples
The following code illustrates how to set backward forecast value for IChartTrendLine object.
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"].Value2 = -1;
sheet.Range["B1"].Value2 = 0;
sheet.Range["C1"].Value2 = 1;
sheet.Range["A2"].Value2 = 10;
sheet.Range["B2"].Value2 = 20;
sheet.Range["C2"].Value2 = 30;
//Create chart
IChart chart = sheet.Charts.Add();
//Add serie
IChartSerie serie = chart.Series.Add();
//Set serie Y Values
serie.Values = sheet.Range["A2:C2"];
//Set serie X Values
serie.CategoryLabels = sheet.Range["A1:C1"];
//Set chart type
chart.ChartType = ExcelChartType.Scatter_Markers;
//Set X axis minimum and maximum values
chart.PrimaryCategoryAxis.MinimumValue = -2;
chart.PrimaryCategoryAxis.MaximumValue = 2;
//Get chart trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set backward forecast value
trendline.Backward = 3;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Border
Represents border object. Read-only.
Declaration
IChartBorder Border { get; }
Property Value
Type |
---|
IChartBorder |
Examples
The following code illustrates how to access and format the IChartBorder for IChartTrendLine
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"].Value2 = 10;
sheet.Range["B2"].Value2 = 20;
sheet.Range["C2"].Value2 = 30;
//Create chart
IChart chart = sheet.Charts.Add();
//Add serie
IChartSerie serie = chart.Series.Add();
//Set serie Y Values
serie.Values = sheet.Range["A2:C2"];
//Set serie X Values
serie.CategoryLabels = sheet.Range["A1:C1"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set trendline broder properties
trendline.Border.ColorIndex = ExcelKnownColors.Red;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Chart3DOptions
Gets the IThreeDFormat object. Read-only.[Deprecated]
Declaration
IThreeDFormat Chart3DOptions { get; }
Property Value
Type |
---|
IThreeDFormat |
DataLabel
Returns data label. Read-only.
Declaration
IChartTextArea DataLabel { get; }
Property Value
Type |
---|
IChartTextArea |
Remarks
To get DataLabel DisplayRSquared or DisplayEquation must be set to true. Otherwise exception will be thrown.
Examples
The following code illustrates how to enable and set IChartTextArea text for IChartTrendLine object.
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 trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Enable trendline data label by DisplayRSquared
trendline.DisplayRSquared = true;
//Set data label text
trendline.DataLabel.Text = "y=10*x";
//Get trendline data label Text
Console.WriteLine(trendline.DataLabel.Text);
//Save and Dispose
workbook.SaveAs("Chart.xls");
workbook.Close();
Console.ReadKey();
}
//Output will be
// y=10*x
DisplayEquation
True if the equation for the trend line is displayed on the chart.
Declaration
bool DisplayEquation { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to display equation for IChartTrendLine object.
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 trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set equation in trendline
trendline.DisplayEquation = true;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
DisplayRSquared
True if the R-squared value of the trend line is displayed on the chart.
Declaration
bool DisplayRSquared { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to display RSquared value for IChartTrendLine object.
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 trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set RSquared value for trendline
trendline.DisplayRSquared = true;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Forward
Represents number of periods that the trend line extends forward.
Declaration
double Forward { get; set; }
Property Value
Type |
---|
System.Double |
Examples
The following code illustrates how to set Forward forecast value for IChartTrendLine object.
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"].Value2 = -1;
sheet.Range["B1"].Value2 = 0;
sheet.Range["C1"].Value2 = 1;
sheet.Range["A2"].Value2 = 10;
sheet.Range["B2"].Value2 = 20;
sheet.Range["C2"].Value2 = 30;
//Create chart
IChart chart = sheet.Charts.Add();
//Add serie
IChartSerie serie = chart.Series.Add();
//Set serie Y Values
serie.Values = sheet.Range["A2:C2"];
//Set serie X Values
serie.CategoryLabels = sheet.Range["A1:C1"];
//Set chart type
chart.ChartType = ExcelChartType.Scatter_Markers;
//Set X axis minimum and maximum values
chart.PrimaryCategoryAxis.MinimumValue = -2;
chart.PrimaryCategoryAxis.MaximumValue = 2;
//Get chart trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set forward forecast value
trendline.Forward = 3;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Intercept
Represents point where the trend line crosses the value axis.
Declaration
double Intercept { get; set; }
Property Value
Type |
---|
System.Double |
Examples
The following code illustrates how to set intercept value for IChartTrendLine object.
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"].Value2 = 1;
sheet.Range["B1"].Value2 = 2;
sheet.Range["C1"].Value2 = 3;
sheet.Range["A2"].Value2 = 10;
sheet.Range["B2"].Value2 = 20;
sheet.Range["C2"].Value2 = 30;
//Create chart
IChart chart = sheet.Charts.Add();
//Add serie
IChartSerie serie = chart.Series.Add();
//Set serie Y Values
serie.Values = sheet.Range["A2:C2"];
//Set serie X Values
serie.CategoryLabels = sheet.Range["A1:C1"];
//Set chart type
chart.ChartType = ExcelChartType.Scatter_Markers;
//Get chart trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set intercept value
trendline.Intercept = 10;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
InterceptIsAuto
True if the point where the trend line crosses the value axis is automatically determined by the regression.
Declaration
bool InterceptIsAuto { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to check whether the IChartTrendLine object intercept value is automatic or not.
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"].Value2 = 1;
sheet.Range["B1"].Value2 = 2;
sheet.Range["C1"].Value2 = 3;
sheet.Range["A2"].Value2 = 10;
sheet.Range["B2"].Value2 = 20;
sheet.Range["C2"].Value2 = 30;
//Create chart
IChart chart = sheet.Charts.Add();
//Add serie
IChartSerie serie = chart.Series.Add();
//Set serie Y Values
serie.Values = sheet.Range["A2:C2"];
//Set serie X Values
serie.CategoryLabels = sheet.Range["A1:C1"];
//Set chart type
chart.ChartType = ExcelChartType.Scatter_Markers;
//Get chart trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set intercept value
trendline.Intercept = 10;
//Check trendline intercept is automatic
Console.WriteLine("Is Trendline Intercept value is automatic:" + trendline.InterceptIsAuto.ToString());
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
// Output will be
// Is Trendline Intercept value is automatic:False
Name
Gets or Sets the name of trend line.
Declaration
string Name { get; set; }
Property Value
Type |
---|
System.String |
Examples
The following code illustrates how to access name from IChartTrendLine object.
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 trendline
IChartTrendLine trendline = trendLines.Add(ExcelTrendLineType.Logarithmic);
//Get trendline Name
Console.WriteLine(trendline.Name);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
// Log. (Serie3)
NameIsAuto
Represents whether the trendline name is default or not.
Declaration
bool NameIsAuto { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to check whether the IChartTrendLine object name is default or not.
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 trendline
IChartTrendLine trendline = trendLines.Add(ExcelTrendLineType.Logarithmic);
//Set trendline name
trendline.Name = "Trendline 1";
//Check trendline name is automatic
Console.WriteLine(trendline.NameIsAuto);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
// False
Order
Represents for Moving Average and Polynomial trend line type order value.
Declaration
int Order { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set order value for IChartTrendLine object.
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"].Value2 = 10;
sheet.Range["B2"].Value2 = 20;
sheet.Range["C2"].Value2 = 30;
//Create chart
IChart chart = sheet.Charts.Add();
//Add serie
IChartSerie serie = chart.Series.Add();
//Set serie Y Values
serie.Values = sheet.Range["A2:C2"];
//Set serie X Values
serie.CategoryLabels = sheet.Range["A1:C1"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set trendline type
trendline.Type = ExcelTrendLineType.Polynomial;
//Set trendline order
trendline.Order = 6;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Shadow
Gets the shadow.Read-only.
Declaration
IShadow Shadow { get; }
Property Value
Type |
---|
IShadow |
Examples
The following code illustrates how to access and format the IShadow for IChartTrendLine
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"].Value2 = 10;
sheet.Range["B2"].Value2 = 20;
sheet.Range["C2"].Value2 = 30;
//Create chart
IChart chart = sheet.Charts.Add();
//Add serie
IChartSerie serie = chart.Series.Add();
//Set serie Y Values
serie.Values = sheet.Range["A2:C2"];
//Set serie X Values
serie.CategoryLabels = sheet.Range["A1:C1"];
//Set chart type
chart.ChartType = ExcelChartType.Column_Clustered;
//Get chart trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set trendline shadow color
trendline.Shadow.ShadowColor = System.Drawing.Color.Red;
//Set trendline shadow outer presets
trendline.Shadow.ShadowOuterPresets = Excel2007ChartPresetsOuter.OffsetDiagonalTopRight;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Type
Gets or Sets trend line type.
Declaration
ExcelTrendLineType Type { get; set; }
Property Value
Type |
---|
ExcelTrendLineType |
Examples
The following code illustrates how to set ExcelTrendLineType for IChartTrendLine object.
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 trendline
IChartTrendLine trendline = trendLines.Add();
//Set trendline type
trendline.Type = ExcelTrendLineType.Polynomial;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Methods
ClearFormats()
Clears current trend line formats.
Declaration
void ClearFormats()
Examples
The following code illustrates how to clear the formats of IChartTrendLine object.
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 trendlines collection
IChartTrendLines trendLines = serie.TrendLines;
//Add trendline
IChartTrendLine trendline = trendLines.Add();
//Set RSquared value for trendline
trendline.DisplayRSquared = true;
//Set trendline border color
trendline.Border.ColorIndex = ExcelKnownColors.Red;
//Set trendline name
trendline.Name = "trendline 1";
//Check trendline before clearing the formats
Console.WriteLine("Before clearing the formats\n------");
Console.WriteLine("Is default line color applied in trendline:" + trendline.Border.IsAutoLineColor);
Console.WriteLine("Trendline name:" + trendline.Name);
Console.WriteLine("Is R-squared value displayed:" + trendline.DisplayRSquared);
//Clear the trendline formats
trendline.ClearFormats();
//Check trendline after clearing the formats
Console.WriteLine("After clearing the formats\n------");
Console.WriteLine("Is default line color applied in trendline:" + trendline.Border.IsAutoLineColor);
Console.WriteLine("Trendline name:" + trendline.Name);
Console.WriteLine("Is R-squared value displayed:" + trendline.DisplayRSquared);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
// Output will be
// Before clearing the formats
//------
//Is default line color applied in trendline:False
//Trendline name:trendline 1
//Is R-squared value displayed:True
//After clearing the formats
//------
//Is default line color applied in trendline:True
//Trendline name:Linear (Serie3)
//Is R-squared value displayed:False