public class Trendline extends Line
Example
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.getWorksheets().add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
//Adding a sample value to "A1" cell
worksheet.getCells().get("A1").putValue(50);
//Adding a sample value to "A2" cell
worksheet.getCells().get("A2").putValue(100);
//Adding a sample value to "A3" cell
worksheet.getCells().get("A3").putValue(150);
//Adding a sample value to "A4" cell
worksheet.getCells().get("A4").putValue(200);
//Adding a sample value to "B1" cell
worksheet.getCells().get("B1").putValue(60);
//Adding a sample value to "B2" cell
worksheet.getCells().get("B2").putValue(32);
//Adding a sample value to "B3" cell
worksheet.getCells().get("B3").putValue(50);
//Adding a sample value to "B4" cell
worksheet.getCells().get("B4").putValue(40);
//Adding a sample value to "C1" cell as category data
worksheet.getCells().get("C1").putValue("Q1");
//Adding a sample value to "C2" cell as category data
worksheet.getCells().get("C2").putValue("Q2");
//Adding a sample value to "C3" cell as category data
worksheet.getCells().get("C3").putValue("Y1");
//Adding a sample value to "C4" cell as category data
worksheet.getCells().get("C4").putValue("Y2");
//Adding a chart to the worksheet
int chartIndex = worksheet.getCharts().add(ChartType.COLUMN, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Chart chart = worksheet.getCharts().get(chartIndex);
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.getNSeries().add("A1:B4", true);
//Setting the data source for the category data of NSeries
chart.getNSeries().setCategoryData("C1:C4");
//adding a linear trendline
int index = chart.getNSeries().get(0).getTrendLines().add(TrendlineType.LINEAR);
Trendline trendline = chart.getNSeries().get(0).getTrendLines().get(index);
//Setting the custom name of the trendline.
trendline.setName("Linear");
//Displaying the equation on chart
trendline.setDisplayEquation(true);
//Displaying the R-Squared value on chart
trendline.setDisplayRSquared(true);
//Saving the Excel file
workbook.save("book1.xls");
| Modifier and Type | Method and Description |
|---|---|
double |
getBackward()
Returns or sets the number of periods (or units on a scatter chart) that the trendline extends backward.
|
DataLabels |
getDataLabels()
Represents the DataLabels object for the specified series.
|
boolean |
getDisplayEquation()
Represents if the equation for the trendline is displayed on the chart (in the same data label as the R-squared value).
|
boolean |
getDisplayRSquared()
Represents if the R-squared value of the trendline is displayed on the chart (in the same data label as the equation).
|
double |
getForward()
Returns or sets the number of periods (or units on a scatter chart) that the trendline extends forward.
|
double |
getIntercept()
Returns or sets the point where the trendline crosses the value axis.
|
LegendEntry |
getLegendEntry()
Gets the legend entry according to this trendline
|
java.lang.String |
getName()
Returns the name of the trendline.
|
int |
getOrder()
Returns or sets the trendline order (an integer greater than 1) when the trendline type is Polynomial.
|
int |
getPeriod()
Returns or sets the period for the moving-average trendline.
|
int |
getType()
Returns the trendline type.
|
boolean |
isInterceptAuto()
Indicates whether Microsoft Workbook automatically determines the intercept of the trendline.
|
boolean |
isNameAuto()
Returns if Microsoft Excel automatically determines the name of the trendline.
|
void |
setBackward(double value)
Returns or sets the number of periods (or units on a scatter chart) that the trendline extends backward.
|
void |
setDisplayEquation(boolean value)
Represents if the equation for the trendline is displayed on the chart (in the same data label as the R-squared value).
|
void |
setDisplayRSquared(boolean value)
Represents if the R-squared value of the trendline is displayed on the chart (in the same data label as the equation).
|
void |
setForward(double value)
Returns or sets the number of periods (or units on a scatter chart) that the trendline extends forward.
|
void |
setIntercept(double value)
Returns or sets the point where the trendline crosses the value axis.
|
void |
setInterceptAuto(boolean isInterceptAuto)
Sets whether Microsoft Workbook automatically determines the intercept of the trendline.
|
void |
setName(java.lang.String value)
Returns the name of the trendline.
|
void |
setNameAuto(boolean value)
Returns if Microsoft Excel automatically determines the name of the trendline.
|
void |
setOrder(int value)
Returns or sets the trendline order (an integer greater than 1) when the trendline type is Polynomial.
|
void |
setPeriod(int value)
Returns or sets the period for the moving-average trendline.
|
getBeginArrowLength, getBeginArrowWidth, getBeginType, getCapType, getColor, getCompoundType, getDashType, getEndArrowLength, getEndArrowWidth, getEndType, getFormattingType, getGradientFill, getJoinType, getStyle, getThemeColor, getTransparency, getWeight, getWeightPt, getWeightPx, isAuto, isAutomaticColor, isVisible, setAuto, setBeginArrowLength, setBeginArrowWidth, setBeginType, setCapType, setColor, setCompoundType, setDashType, setEndArrowLength, setEndArrowWidth, setEndType, setFormattingType, setJoinType, setStyle, setThemeColor, setTransparency, setVisible, setWeight, setWeightPt, setWeightPxpublic boolean isNameAuto()
public void setNameAuto(boolean value)
public int getType()
See TrendlineType.
public java.lang.String getName()
public void setName(java.lang.String value)
public int getOrder()
public void setOrder(int value)
public int getPeriod()
Remarks
This value should be between 2 and 255. And it must be less than the number of the chart points in the seriespublic void setPeriod(int value)
Remarks
This value should be between 2 and 255. And it must be less than the number of the chart points in the seriespublic double getForward()
public void setForward(double value)
public double getBackward()
public void setBackward(double value)
public boolean getDisplayEquation()
public void setDisplayEquation(boolean value)
public boolean getDisplayRSquared()
public void setDisplayRSquared(boolean value)
public double getIntercept()
public void setIntercept(double value)
public DataLabels getDataLabels()
public LegendEntry getLegendEntry()
public boolean isInterceptAuto()
public void setInterceptAuto(boolean isInterceptAuto)
See Also:
Aspose.Cells Documentation - the home page for the Aspose.Cells Product Documentation.
Aspose.Cells Support Forum - our preferred method of support.
We guarantee a prompt response to any inquiry!
© Aspose Pty Ltd 2003-2025. All Rights Reserved.