[]
A trendline shows the trend, or direction, of data in a series. Use this interface to configure how the trendline is calculated and displayed, such as its type, forward or backward projection, equation, and R-squared value.
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Month", "Sales"}, {"Jan", 10}, {"Feb", 15}, {"Mar", 18}, {"Apr", 24}
});
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 200, 30, 300, 300);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:B5"), RowCol.Columns, true, true);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setType(TrendlineType.Linear);
voidvoiddelete()doublebooleanbooleandoubleintgetIndex()doublegetName()booleanintgetOrder()TrendlineType.Polynomial.intgetType()voidsetBackward(double value) voidsetDisplayEquation(boolean value) voidsetDisplayRSquared(boolean value) voidsetForward(double value) voidsetIntercept(double value) voidvoidsetNameIsAuto(boolean value) voidsetOrder(int value) TrendlineType.Polynomial.voidsetPeriod(int value) voidsetType(TrendlineType value) The index identifies the trendline's position among similar objects in the same collection.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
int index = trendline.getIndex();
Use this property to read the backward forecast length configured for the trendline. For scatter charts, the returned value represents units on the horizontal axis rather than category periods.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setBackward(0.5);
double backward = trendline.getBackward();
Use this property to set the backward forecast length configured for the trendline. For scatter charts, the value represents units on the horizontal axis rather than category periods.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setBackward(0.5);
value - The number of periods, or units on a scatter chart, that the trendline extends backward.If this property is true, the equation is shown in the same data label as the R-squared value. Use setDisplayEquation(boolean) to enable or disable the equation display.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setDisplayEquation(true);
boolean displayEquation = trendline.getDisplayEquation();
true if the trendline equation is displayed on the chart; otherwise, false.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setDisplayEquation(true);
value - true if the trendline equation is displayed on the chart; otherwise, false.If this property is true, the R-squared value is displayed on the chart in the same data label as the trendline equation. Enabling this setting also turns on data labels. See getDataLabel() and setDisplayRSquared(boolean).
worksheet.getRange("A1:B4").setValue(new Object[][] {
{1, 2},
{2, 4},
{3, 6},
{4, 8}
});
IShape shape = worksheet.getShapes().addChart(ChartType.XYScatter, 20, 20, 360, 230);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:B4"), RowCol.Columns, false, false);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setDisplayRSquared(true);
boolean displayRSquared = trendline.getDisplayRSquared();
true if the trendline displays its R-squared value; otherwise, false.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{1, 2},
{2, 4},
{3, 6},
{4, 8}
});
IShape shape = worksheet.getShapes().addChart(ChartType.XYScatter, 20, 20, 360, 230);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:B4"), RowCol.Columns, false, false);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setDisplayRSquared(true);
value - true if the trendline displays its R-squared value; otherwise, false.The returned IChartFormat object provides access to the trendline's fill and line formatting settings.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
IChartFormat format = trendline.getFormat();
format.getLine().getColor().setRGB(Color.GetBlue());
IChartFormat object that represents the trendline formatting.Use this property to read the forecast length configured for the trendline. For scatter charts, the returned value represents units on the horizontal axis rather than category periods.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setForward(1.5);
double forward = trendline.getForward();
Use this property to set the forecast length configured for the trendline. For scatter charts, the value represents units on the horizontal axis rather than category periods.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setForward(1.5);
value - The number of periods, or units on a scatter chart, that the trendline extends forward.Returns the fixed intercept value when the trendline intercept has been set explicitly.
worksheet.getRange("A1:B5").setValue(new Object[][] {
{1, 2},
{2, 4},
{3, 6},
{4, 8},
{5, 10}
});
IChart chart = worksheet.getShapes().addChart(ChartType.XYScatter, 20, 20, 300, 200).getChart();
chart.setSourceData(worksheet.getRange("A1:B5"));
ITrendline trendline = chart.getSeriesCollection().get(0).getTrendlines().add();
trendline.setIntercept(1.5);
double intercept = trendline.getIntercept();
Sets the fixed intercept value when the trendline intercept has been set explicitly.
worksheet.getRange("A1:B5").setValue(new Object[][] {
{1, 2},
{2, 4},
{3, 6},
{4, 8},
{5, 10}
});
IChart chart = worksheet.getShapes().addChart(ChartType.XYScatter, 20, 20, 300, 200).getChart();
chart.setSourceData(worksheet.getRange("A1:B5"));
ITrendline trendline = chart.getSeriesCollection().get(0).getTrendlines().add();
trendline.setIntercept(1.5);
value - The point where the trendline crosses the value axis.Returns the custom name assigned to the trendline. If the trendline name is determined automatically, this method returns the current automatically generated name.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setName("Sales Trend");
String name = trendline.getName();
Sets the custom name assigned to the trendline. If the trendline name is determined automatically, this method Sets the current automatically generated name.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setName("Sales Trend");
name - The trendline name.When this property is true, the trendline uses an automatically generated name. When it is false, the name can be controlled explicitly, for example by using setName(String).
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setNameIsAuto(false);
boolean nameIsAuto = trendline.getNameIsAuto();
true if the trendline's name is automatically determined; otherwise, false.When this property is true, the trendline uses an automatically generated name. When it is false, the name can be controlled explicitly, for example by using setName(String).
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setNameIsAuto(false);
value - true if the trendline's name is automatically determined; otherwise, false.TrendlineType.Polynomial. The order specifies the degree of the polynomial trendline.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setType(TrendlineType.Polynomial);
trendline.setOrder(3);
int order = trendline.getOrder();
TrendlineType.Polynomial. The order specifies the degree of the polynomial trendline.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setType(TrendlineType.Polynomial);
trendline.setOrder(3);
value - The trendline order.Use this method to access the ISeries that contains the current trendline.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
ISeries parentSeries = trendline.getParent();
ISeries that contains the trendline.This property applies to a trendline whose type is TrendlineType.MovingAvg.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setType(TrendlineType.MovingAvg);
trendline.setPeriod(2);
int period = trendline.getPeriod();
This property applies to a trendline whose type is TrendlineType.MovingAvg.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setType(TrendlineType.MovingAvg);
trendline.setPeriod(2);
value - The period of the moving-average trendline.Returns a TrendlineType value that specifies how the trendline is calculated.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setType(TrendlineType.Linear);
TrendlineType type = trendline.getType();
Use this method to change how the trendline is calculated for the associated series.
worksheet.getRange("A1:B5").setValue(new Object[][] {
{"Month", "Sales"},
{"Jan", 12},
{"Feb", 18},
{"Mar", 15},
{"Apr", 21}
});
IChart chart = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 300, 200).getChart();
chart.getSeriesCollection().add(worksheet.getRange("A1:B5"), RowCol.Columns, true, false);
ITrendline trendline = chart.getSeriesCollection().get(0).getTrendlines().add();
trendline.setType(TrendlineType.Linear);
value - The trendline type to apply.The returned IDataLabel object can be used to configure the content and formatting of the trendline label displayed on the chart.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.setDisplayEquation(true);
IDataLabel dataLabel = trendline.getDataLabel();
dataLabel.getFormat().getFill().getColor().setRGB(Color.GetRed());
IDataLabel object that represents the data label associated with the trendline.Use this method to remove custom formatting that has been applied to the trendline.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.getFormat().getLine().getColor().setRGB(Color.GetBlue());
trendline.clearFormats();
After this method is called, the trendline is removed from its parent chart series.
worksheet.getRange("A1:A4").setValue(new Object[] { 10, 20, 30, 40 });
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 20, 20, 360, 220);
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:A4"), RowCol.Columns);
ITrendline trendline = shape.getChart().getSeriesCollection().get(0).getTrendlines().add();
trendline.delete();