Class ExcelChartConfig

java.lang.Object
io.github.dornol.excelkit.excel.ExcelChartConfig

public class ExcelChartConfig extends Object
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
  • 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

      public ExcelChartConfig title(String title)
      Sets the chart title.
      Parameters:
      title - the chart title
      Returns:
      this config for chaining
    • categoryColumn

      public ExcelChartConfig categoryColumn(int columnIndex)
      Sets the category (X-axis) column index (0-based).
      Parameters:
      columnIndex - 0-based column index for categories
      Returns:
      this config for chaining
    • valueColumn

      public ExcelChartConfig valueColumn(int columnIndex, String seriesTitle)
      Adds a value (Y-axis) series from the specified column.
      Parameters:
      columnIndex - 0-based column index for values
      seriesTitle - title of this data series
      Returns:
      this config for chaining
    • position

      public ExcelChartConfig position(int col1, int row1, int col2, int row2)
      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

      public ExcelChartConfig categoryAxisTitle(String title)
      Sets the category axis (X-axis) title.
      Parameters:
      title - the axis title, or null to omit
      Returns:
      this config for chaining
      Since:
      0.6.1
    • valueAxisTitle

      public ExcelChartConfig valueAxisTitle(String title)
      Sets the value axis (Y-axis) title.
      Parameters:
      title - the axis title, or null to omit
      Returns:
      this config for chaining
      Since:
      0.6.1
    • legendPosition

      public ExcelChartConfig legendPosition(ExcelChartConfig.LegendPosition position)
      Sets the legend position. If null (the default), no legend is added.
      Parameters:
      position - the legend position, or null for no legend
      Returns:
      this config for chaining
      Since:
      0.6.1
    • showDataLabels

      public ExcelChartConfig showDataLabels(boolean show)
      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 - true to show data labels
      Returns:
      this config for chaining
      Since:
      0.6.1
    • barGrouping

      public ExcelChartConfig barGrouping(ExcelChartConfig.BarGrouping grouping)
      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

      public ExcelChartConfig barDirection(ExcelChartConfig.BarDirection direction)
      Sets the bar direction for bar charts. ExcelChartConfig.BarDirection.VERTICAL renders columns; ExcelChartConfig.BarDirection.HORIZONTAL renders horizontal bars. Ignored for non-bar chart types.
      Parameters:
      direction - the bar direction
      Returns:
      this config for chaining
      Since:
      0.6.1