
Sheet.getCellRange("B4").setNumberValue(9000) Ĭhart chart = sheet.getCharts().add(ExcelChartType.Doughnut) ĬtDataRange(sheet.getCellRange("A1:B5")) ĬtChartTitle("Market share by country") įor (int i = 0 i < series.Learn everything about creating and formatting a Pie chart in Excel. Sheet.getCellRange("B3").setNumberValue(8000) Sheet.getCellRange("B2").setNumberValue(6000) Sheet.getCellRange("A5").setValue("Japan")
Sheet.getCellRange("A4").setValue("German") Sheet.getCellRange("A3").setValue("Mexico")
Sheet.getCellRange("A2").setValue("Cuba") Sheet.getCellRange("A1").setValue("Country")
Set the legend position of the chart using Chart.getLegend().setPosition() method. Add a doughnut chart to the worksheet using Worksheet.getCharts().add(ExcelChartType.Doughnut) method. Workbook.saveToFile("PieChart.xlsx", ExcelVersion.Version2016) Sheet.getCellRange("B2:C5").getCellStyle().setNumberFormat("\"$\"#,#0") Ĭhart chart = sheet.getCharts().add(ExcelChartType.Pie) ĬtDataRange(sheet.getCellRange("B2:B5")) ĬhartSerie cs = chart.getSeries().get(0) Ĭs.setCategoryLabels(sheet.getCellRange("A2:A5")) Ĭs.setValues(sheet.getCellRange("B2:B5")) Ĭs.getDataPoints().getDefaultDataPoint().getDataLabels().hasValue(true) Sheet.getCellRange("A1:B5").getCellStyle().setHorizontalAlignment(HorizontalAlignType.Center) Sheet.getCellRange("A1:B5").getCellStyle().setVerticalAlignment(VerticalAlignType.Center) Sheet.getCellRange("A1:B1").getCellStyle().getExcelFont().setColor(Color.white) Sheet.getCellRange("A1:B1").getCellStyle().setColor(Color.darkGray) Sheet.getCellRange("A1:B1").setRowHeight(15) Sheet.getCellRange("B5").setNumberValue(8500) Sheet.getCellRange("B4").setNumberValue(7000) Sheet.getCellRange("B3").setNumberValue(6000) Sheet.getCellRange("B2").setNumberValue(4000) Sheet.getCellRange("B1").setValue("Sales")
Sheet.getCellRange("A1").setValue("Year") Worksheet sheet = workbook.getWorksheets().get(0)
Save the result file using Workbook.saveToFile() method. Get a specified series in the chart and set category labels and values for the series using tCategoryLabels() and ChartSerie. Set the position and title of the chart. Set data range for the chart using tDataRange() method. Add a pie chart to the worksheet using Worksheet.getCharts().add(ExcelChartType.Pie) method. Add some data to specified cells and set the cell styles.
Get a specified worksheet using Workbook.getWorksheets().get() method.