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>
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);}}
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse