Add Trendline to Excel Chart in Java

Import JAR Dependency (2 Method)

import com.spire.xls.*;
import com.spire.xls.core.IChartTrendLine;

import java.awt.*;

public class AddTrendline {
public static void main(String[] args){
//Create a Workbook instance
Workbook workbook = new Workbook();

//Load the Excel file

//Get the first chart in the first worksheet
Chart chart = workbook.getWorksheets().get(0).getCharts().get(0);

//Add a Trendline to the first series of the chart
IChartTrendLine trendLine = chart.getSeries().get(0).getTrendLines().add(TrendLineType.Linear);

//Set Trendline name

//Set line type and color

//Set forward and backward value

//Display equation on chart

//Display R-Squared value on chart

//Save the result file
workbook.saveToFile("AddTrendline.xlsx", ExcelVersion.Version2013);




Sharing Java Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Start using Azure DevOps REST API in C#

Landmannalaugar direction route sign

My Python Collection In Illumination

A drawing the the human gut

How to move Windows 10 to an SSD

Ease Your Load: Level Loading Made Easy

Pixel Shift Motion Correction — iOS

Supporting entry-level engineers

Redis — Getting Notified When a Key is Expired or Changed

Double Jump in Unity

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Wilson

Andrew Wilson

Sharing Java Code

More from Medium

Create a Line Chart in Excel in Java

Open-source SPL that can execute SQL without RDB

AWS RDS Connect with Java

TIL 0520 Java8 practice 2