Package io.github.dornol.excelkit.excel
Class ExcelChartConfig
java.lang.Object
io.github.dornol.excelkit.excel.ExcelChartConfig
Builder for creating charts in an Excel sheet.
Supports bar, line, and pie charts. Charts are rendered using Apache POI's XDDF chart API and reference cell ranges for their data.
ExcelWriter.<Product>create()
.column("Name", Product::getName)
.column("Sales", Product::getSales, c -> c.type(ExcelDataType.INTEGER))
.chart(chart -> chart
.type(ExcelChartConfig.ChartType.BAR)
.title("Sales by Product")
.categoryColumn(0)
.valueColumn(1, "Sales")
.categoryAxisTitle("Product")
.valueAxisTitle("Amount")
.legendPosition(ExcelChartConfig.LegendPosition.BOTTOM)
.barDirection(ExcelChartConfig.BarDirection.HORIZONTAL)
.barGrouping(ExcelChartConfig.BarGrouping.STACKED)
.showDataLabels(true)
.position(3, 0, 20, 8))
.write(stream)
.write(out);
- Since:
- 0.6.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumBar chart direction.static enumBar chart grouping mode.static enumSupported chart types.static enumLegend position relative to the chart area. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbarDirection(ExcelChartConfig.BarDirection direction) Sets the bar direction for bar charts.barGrouping(ExcelChartConfig.BarGrouping grouping) Sets the bar grouping mode for bar charts.categoryAxisTitle(String title) Sets the category axis (X-axis) title.categoryColumn(int columnIndex) Sets the category (X-axis) column index (0-based).Sets the legend position.position(int col1, int row1, int col2, int row2) Sets the chart position in the sheet.showDataLabels(boolean show) Sets whether data labels (values) are shown on chart data points.Sets the chart title.Sets the chart type.valueAxisTitle(String title) Sets the value axis (Y-axis) title.valueColumn(int columnIndex, String seriesTitle) Adds a value (Y-axis) series from the specified column.
-
Constructor Details
-
ExcelChartConfig
public ExcelChartConfig()Creates a new chart configuration with defaults.
-
-
Method Details
-
type
Sets the chart type.- Parameters:
type- the chart type- Returns:
- this config for chaining
-
title
Sets the chart title.- Parameters:
title- the chart title- Returns:
- this config for chaining
-
categoryColumn
Sets the category (X-axis) column index (0-based).- Parameters:
columnIndex- 0-based column index for categories- Returns:
- this config for chaining
-
valueColumn
Adds a value (Y-axis) series from the specified column.- Parameters:
columnIndex- 0-based column index for valuesseriesTitle- title of this data series- Returns:
- this config for chaining
-
position
Sets the chart position in the sheet.- Parameters:
col1- starting column (0-based)row1- starting row (0-based)col2- ending column (0-based)row2- ending row (0-based)- Returns:
- this config for chaining
-
categoryAxisTitle
Sets the category axis (X-axis) title.- Parameters:
title- the axis title, ornullto omit- Returns:
- this config for chaining
- Since:
- 0.6.1
-
valueAxisTitle
Sets the value axis (Y-axis) title.- Parameters:
title- the axis title, ornullto omit- Returns:
- this config for chaining
- Since:
- 0.6.1
-
legendPosition
Sets the legend position. Ifnull(the default), no legend is added.- Parameters:
position- the legend position, ornullfor no legend- Returns:
- this config for chaining
- Since:
- 0.6.1
-
showDataLabels
Sets whether data labels (values) are shown on chart data points.Note: data label rendering is best-effort and depends on the chart type and Apache POI's XDDF support.
- Parameters:
show-trueto show data labels- Returns:
- this config for chaining
- Since:
- 0.6.1
-
barGrouping
Sets the bar grouping mode for bar charts. Ignored for non-bar chart types.- Parameters:
grouping- the bar grouping mode- Returns:
- this config for chaining
- Since:
- 0.6.1
-
barDirection
Sets the bar direction for bar charts.ExcelChartConfig.BarDirection.VERTICALrenders columns;ExcelChartConfig.BarDirection.HORIZONTALrenders horizontal bars. Ignored for non-bar chart types.- Parameters:
direction- the bar direction- Returns:
- this config for chaining
- Since:
- 0.6.1
-