Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

CodeSharing
CodeSharing

Posted on

     

Create Pivot Chart in Excel using Java

In my previous posts, I've introducedhow to create an Excel pivot table with the 3rd party library--Free Spire.XLS for Java. This article will demonstrates how to create a pivot chart based on the data in pivot table.

Installation
Method 1: Download theFree Spire.XLS for Java and unzip it, then add the Spire.Xls.jar file to your project as dependency.

Method 2: Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.

<repositories><repository><id>com.e-iceblue</id><name>e-iceblue</name><url>http://repo.e-iceblue.com/nexus/content/groups/public/</url></repository></repositories><dependencies><dependency><groupId>e-iceblue</groupId><artifactId>spire.xls.free</artifactId><version>3.9.1</version></dependency></dependencies>
Enter fullscreen modeExit fullscreen mode

Java Code:

importcom.spire.xls.*;importcom.spire.xls.core.IPivotTable;publicclassCreatePivotChart{publicstaticvoidmain(String[]args){//Load the Excel fileWorkbookworkbook=newWorkbook();workbook.loadFromFile("data.xlsx");//Get the first worksheetWorksheetsheet=workbook.getWorksheets().get(0);//get the first pivot table in the worksheetIPivotTablepivotTable=sheet.getPivotTables().get(0);//Add a clustered column chart based on the pivot table dataChartchart=sheet.getCharts().add(ExcelChartType.ColumnClustered,pivotTable);//Set chart positionchart.setTopRow(14);chart.setBottomRow(25);//Set chart titlechart.setChartTitle("Total");//Save the result fileworkbook.saveToFile("CreatPivotChart.xlsx",ExcelVersion.Version2013);}}
Enter fullscreen modeExit fullscreen mode

Alt Text

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Sharing code to help developers deal with their files in Java applications.
  • Joined

More fromCodeSharing

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp