Class Chart.Builder
- Enclosing class:
- Chart
Chart. Start it with a type method such as
Chart.column(), set the anchor and the series, then call
build() and pass the result to Sheet.addChart. Series
options (pointFill(int, io.keikai.axyra.sheets.style.Color), dataLabels(io.keikai.axyra.sheets.content.DataLabels), trendline(io.keikai.axyra.sheets.content.Trendline),
seriesType(java.lang.String), ...) apply to the series added last. Tokens and
numbers are checked only when the chart is added.
Chart chart = Chart.column()
.title("Revenue")
.anchor(1, 4, 16, 12) // E2 to the top-left of M17
.series("Revenue", "Sheet1!$B$2:$B$9", "Sheet1!$A$2:$A$9")
.build();
int index = sheet.addChart(chart);
-
Method Summary
Modifier and TypeMethodDescriptionanchor(int fromRow, int fromColumn, int toRow, int toColumn) Sets the two-cell anchor (0-based).anchorOffsets(int fromColOff, int fromRowOff, int toColOff, int toRowOff) The sub-cell EMU offsets of the two-cell anchor's from/to corners (914400 EMU = 1 inch).autoTitle(boolean on) Mark the chart as carrying an Excel "auto" title: no explicit text is emitted, so the app derives the displayed title from the single series name.The solid a 3-D bar or column is drawn as —<c:shape>, ECMA-376 Part 1 §21.2.2.177:"box"(the default),"cone","coneToMax","cylinder","pyramid"or"pyramidToMax".bubbleSeries(String name, String valuesRef, String categoriesRef, String sizesRef) Add a bubble series: a values (Y) range, a categories (X) range and the sizes (Z) range that gives each bubble its area —<c:bubbleSize>, ECMA-376 Part 1 §21.2.2.19.bubbleSizes(String sizesRef) Attaches a bubble-size (Z) range to the series most recently added — the counterpart ofpointFill(int, io.keikai.axyra.sheets.style.Color)for a series that was added with one of the plainseries(...)overloads.build()The immutable chart.categoryAxisTitle(String title) Sets the category (X) axis title;nullsets none.categoryAxisVisible(boolean visible) Shows or hides the category (X) axis; shown by default (ECMA-376 §21.2.2.16 catAx).chartAreaBorder(Color color) Sets the chart-area border color.chartAreaFill(Color fill) Chart-area fill color (ECMA-376 §21.2.2.198<c:spPr>on the chart space).Suppress the chart-area frame (<a:ln><a:noFill/></a:ln>).Make the chart-area background explicitly TRANSPARENT (<a:noFill/>, ECMA-376 §20.1.8.44) so the sheet shows through — distinct from leaving the fill unset, which renders as the application-default opaque white.Drop every series this builder currently holds.dataLabels(DataLabels labels) Attach data labels to the most recently added series.Attach error bars to the most recently added series.extendedApparatus(String chartExBase64, String colorsBase64, String styleBase64) Carry the byte-exact apparatus of a modern extended (cx:) chart — thechartExpart plus itschartColorStyle/chartStyleparts, each base64-encoded — so a re-authored waterfall/funnel/… re-emits the complete part set Excel requires to open the file.gapWidth(int percent) Sets the gap between bar or column clusters, as a percentage of one bar's width (0–500).Bar/column/area/line grouping:"clustered"/"stacked"/"percentStacked"/"standard"(default"clustered").holeSize(int percent) Sets the doughnut hole size as a percentage of the outer radius; 50 when not set.legend(LegendPosition position) Sets the legend placement.legendLayout(double x, double y, double w, double h) Position the legend at an explicit rectangle in chart-relative fractions (x/ytop-left,w/hsize, all in[0, 1]) — a manual legend layout.legendVisible(boolean visible) Shows or hides the legend without changing its position.overlap(int percent) Sets how much bars in one cluster overlap, as a percentage from -100 (a full bar-width gap) to 100 (full overlap).plotAreaBorder(Color color) Sets the plot-area border color.plotAreaFill(Color fill) Sets the plot-area fill color.plotAreaLayout(double x, double y, double w, double h) Position the inner plot area at an explicit rectangle in chart-relative fractions (ECMA-376 §21.2.2.88manualLayout):x/yare the top-left corner andw/hthe size, all in[0, 1].Suppress the plot-area frame (<a:ln><a:noFill/></a:ln>).Make the plot-area background explicitly transparent (mirrorschartAreaNoFill()).pointExplosion(int pointIndex, int percent) Explode the pie/doughnut slice atpointIndexoutward bypercentof the radius (ECMA-376 §21.2.2.62dPt/explosion) on the most recently added series.Override the fill color of one data point (pie slice / bar) on the most recently added series (ECMA-376 §21.2.2.52 dPt).pointLabel(int pointIndex, String text) Give one point of the most recently added series a label of its own (ECMA-376 §21.2.2.47dLbl) — a caption in place of the value the rest of the series shows.pointLabelHidden(int pointIndex, boolean hidden) Hide the label of one point while the rest of the series keeps its own (<c:dLbl><c:delete val="1"/>).secondaryAxis(boolean on) Plot the most recently added series against a secondary value axis (on) — drawn on the right of the plot with its own scale, the way a ratio or a percentage is shown next to amounts — or against the primary one.Adds a data series with no categories range.Adds a data series with a categories (labels) range.Adds a data series with a solid fill color.seriesType(String type) The plot type of the most recently added series in a combo chart — the plot group it is drawn in (ECMA-376 Part 1 §21.2.2.145: a<c:barChart>,<c:lineChart>,<c:areaChart>or<c:scatterChart>under the one<c:plotArea>).showDataLabels(boolean show) Turns value labels on every series on or off.style(int style) The chart's built-in style number (<c:style val>).threeD(boolean on) Draws the chart in 3-D.Sets a literal chart title and turns offautoTitle.titleFormula(String reference) Makes the chart title follow a cell instead of a literal string (<c:title><c:tx><c:strRef><c:f>).titleLayout(double x, double y, double w, double h) Position the chart title at an explicit rectangle in chart-relative fractions — a manual title layout.Add a trendline to the most recently added series.Change the chart family this spec describes, keeping everything else it already carries — the counterpart ofChart.type()on the read–modify–write path, where the family comes from the file and the caller wants a different one.valueAxisGridlines(boolean on) Show or hide the value (Y) axis' major gridlines — the lines across the plot at each major tick (<c:majorGridlines>, ECMA-376 Part 1 §21.2.2).valueAxisScale(double min, double max) Fixes the value (Y) axis to the range[min, max].valueAxisTitle(String title) Sets the value (Y) axis title;nullsets none.valueAxisVisible(boolean visible) Shows or hides the value (Y) axis; shown by default (ECMA-376 §21.2.2.226 valAx).view3D(int rotX, int rotY, int depthPercent) Render the chart in 3-D with the given view angles (ECMA-376 §21.2.2.228view3D):rotXis the elevation androtYthe rotation, both in degrees;depthPercentis the depth as a percentage of the plot height (100 = default).
-
Method Details
-
title
Sets a literal chart title and turns offautoTitle. -
autoTitle
Mark the chart as carrying an Excel "auto" title: no explicit text is emitted, so the app derives the displayed title from the single series name. Use this instead oftitle(String)to reproduce a source chart whose title was auto (otherwise a rebuild shows a generic "Chart Title"). ECMA-376 §21.2.2.9 (autoTitleDeleted). -
legend
Sets the legend placement.LegendPosition.NONEhides the legend by saving it marked deleted;legendVisible(boolean)hides it by omitting it. Without this call the legend is on the right.- Throws:
NullPointerException- ifpositionis null
-
legendVisible
Shows or hides the legend without changing its position. Hiding omits the<c:legend>element from the saved chart, so every renderer hides it. This differs fromlegend(LegendPosition.NONE), which writes<c:legend><c:delete val="1"/></c:legend>. -
categoryAxisVisible
Shows or hides the category (X) axis; shown by default (ECMA-376 §21.2.2.16 catAx). -
valueAxisVisible
Shows or hides the value (Y) axis; shown by default (ECMA-376 §21.2.2.226 valAx). -
valueAxisGridlines
Show or hide the value (Y) axis' major gridlines — the lines across the plot at each major tick (<c:majorGridlines>, ECMA-376 Part 1 §21.2.2). On by default. On a horizontal bar chart the value axis runs along the bottom, so its gridlines are vertical. -
showDataLabels
Turns value labels on every series on or off. For per-series label content, usedataLabels(DataLabels). -
type
Change the chart family this spec describes, keeping everything else it already carries — the counterpart ofChart.type()on the read–modify–write path, where the family comes from the file and the caller wants a different one.- Parameters:
type- a family token accepted byChart.of(java.lang.String)
-
threeD
Draws the chart in 3-D. Only bar, column, line, pie, area and surface charts have a 3-D form; other types ignore the flag when saved. Set the angles withview3D(int, int, int). -
barShape
The solid a 3-D bar or column is drawn as —<c:shape>, ECMA-376 Part 1 §21.2.2.177:"box"(the default),"cone","coneToMax","cylinder","pyramid"or"pyramidToMax".Only a bar or column chart with
threeD(boolean)set emits it; on any other family the shape has nowhere to go and is ignored, which is also how Excel treats it. An unknown token is read as"box". -
style
The chart's built-in style number (<c:style val>).Excel stores the number and expands the appearance from its own gallery, so this writes exactly what a file carries and no more: a chart saved with a style number opens in Excel wearing that style, and renders here with whatever explicit formatting it was given. Excel's gallery numbers run from 1 to 48. A negative value makes
Sheet.addChartthrowAxyraException. -
titleFormula
Makes the chart title follow a cell instead of a literal string (<c:title><c:tx><c:strRef><c:f>).Pass a sheet-qualified reference such as
"Sheet1!$A$1". Pair it withtitle(String)for the cached text that renderers draw. An empty string clears the link only throughSheet.replaceChart. OnSheet.addChart, leave this unset instead, because an empty reference is written as is. -
grouping
Bar/column/area/line grouping:"clustered"/"stacked"/"percentStacked"/"standard"(default"clustered"). Stacked charts stack each category's series into one bar; without this a rebuilt stacked chart renders as clustered. An unknown token is not rejected and is read as"clustered". -
gapWidth
Sets the gap between bar or column clusters, as a percentage of one bar's width (0–500). When not set, the engine uses the value Excel writes for a new chart: 219 for a clustered 2-D column chart, 182 for a clustered 2-D bar chart, and 150 for stacked, 3-D and other charts. A negative value makesSheet.addChartthrowAxyraException. -
overlap
Sets how much bars in one cluster overlap, as a percentage from -100 (a full bar-width gap) to 100 (full overlap). When not set, the engine uses Excel's value for a new chart: -27 for a clustered 2-D column chart, 0 for every other chart. -
holeSize
Sets the doughnut hole size as a percentage of the outer radius; 50 when not set. Has no effect on other chart types. A negative value makesSheet.addChartthrowAxyraException. -
anchor
Sets the two-cell anchor (0-based). The chart's top-left corner is at the top-left of cell (fromRow,fromColumn). Its bottom-right corner is at the top-left of cell (toRow,toColumn), so that cell is not covered unlessanchorOffsets(int, int, int, int)moves the corner into it. A negative index makesSheet.addChartthrowAxyraException. -
anchorOffsets
The sub-cell EMU offsets of the two-cell anchor's from/to corners (914400 EMU = 1 inch). Excel pins a chart to a fractional position inside the from/to cells; without these the chart snaps to the cell boundary and resizes. Reproduces the exact placement of a source chart.Note the order: column offset before row offset for each corner, unlike
FormControl.Builder.anchorOffsets(long, long, long, long). Offsets are non-negative EMU; a negative value makesSheet.addChartthrowAxyraException. -
chartAreaFill
Chart-area fill color (ECMA-376 §21.2.2.198<c:spPr>on the chart space). Only RGB colors are accepted; the alpha byte is ignored andnullleaves the setting unchanged.- Throws:
IllegalStateException- if the color is a theme, indexed or automatic color
-
chartAreaBorder
Sets the chart-area border color. Only RGB colors are accepted; the alpha byte is ignored andnullleaves the setting unchanged.- Throws:
IllegalStateException- if the color is a theme, indexed or automatic color
-
chartAreaNoBorder
Suppress the chart-area frame (<a:ln><a:noFill/></a:ln>). Use to reproduce a source chart with no outer border box, which a rebuilt chart would otherwise draw by default. -
chartAreaNoFill
Make the chart-area background explicitly TRANSPARENT (<a:noFill/>, ECMA-376 §20.1.8.44) so the sheet shows through — distinct from leaving the fill unset, which renders as the application-default opaque white. Takes precedence overchartAreaFill(Color). -
plotAreaFill
Sets the plot-area fill color. Only RGB colors are accepted; the alpha byte is ignored andnullleaves the setting unchanged.- Throws:
IllegalStateException- if the color is a theme, indexed or automatic color
-
plotAreaBorder
Sets the plot-area border color. Only RGB colors are accepted; the alpha byte is ignored andnullleaves the setting unchanged.- Throws:
IllegalStateException- if the color is a theme, indexed or automatic color
-
plotAreaNoBorder
Suppress the plot-area frame (<a:ln><a:noFill/></a:ln>). -
plotAreaNoFill
Make the plot-area background explicitly transparent (mirrorschartAreaNoFill()). -
series
Adds a data series with no categories range.- Parameters:
name- the series name: literal text or a reference such as"Sheet1!$B$1";nullfor nonevaluesRef- the values range, such as"Sheet1!$B$2:$B$9"
-
series
Adds a data series with a categories (labels) range. On a scatter chartcategoriesRefholds the X values.- Parameters:
name- the series name: literal text or a reference such as"Sheet1!$B$1";nullfor nonevaluesRef- the values range, such as"Sheet1!$B$2:$B$9"categoriesRef- the categories range, ornullfor none
-
clearSeries
Drop every series this builder currently holds.Written for the read–modify–write round trip:
Chart.toBuilder()pre-loads the chart's existing series soseries(...)appends to them, which is right when adding one and wrong when replacing the whole set. Clearing first makes the series list say exactly what the caller means, and nothing else about the chart is touched. -
bubbleSeries
public Chart.Builder bubbleSeries(String name, String valuesRef, String categoriesRef, String sizesRef) Add a bubble series: a values (Y) range, a categories (X) range and the sizes (Z) range that gives each bubble its area —<c:bubbleSize>, ECMA-376 Part 1 §21.2.2.19.Without the sizes every bubble is drawn identically, which is the one dimension a bubble chart exists to show. Only a bubble chart emits them. A
nullsizesRefadds the series without sizes. -
bubbleSizes
Attaches a bubble-size (Z) range to the series most recently added — the counterpart ofpointFill(int, io.keikai.axyra.sheets.style.Color)for a series that was added with one of the plainseries(...)overloads. Does nothing whensizesRefisnullor no series has been added. -
series
Adds a data series with a solid fill color. Only RGB colors are accepted; the alpha byte is ignored andnullleaves the theme color.- Throws:
IllegalStateException- if the color is a theme, indexed or automatic color
-
pointFill
Override the fill color of one data point (pie slice / bar) on the most recently added series (ECMA-376 §21.2.2.52 dPt). Reproduces per-slice colors when rebuilding a chart from its read model.pointIndexis 0-based. Only RGB colors are accepted; the alpha byte is ignored andnullleaves the setting unchanged.- Throws:
IllegalStateException- when no series has been added yet, orfillis a theme, indexed or automatic color
-
pointExplosion
Explode the pie/doughnut slice atpointIndexoutward bypercentof the radius (ECMA-376 §21.2.2.62dPt/explosion) on the most recently added series.pointIndexis 0-based.percentmust be non-negative; 0 means no explosion. A negative value makesSheet.addChartthrowAxyraException.- Throws:
IllegalStateException- when no series has been added yet
-
pointLabel
Give one point of the most recently added series a label of its own (ECMA-376 §21.2.2.47dLbl) — a caption in place of the value the rest of the series shows. Lines are separated by\n.pointIndexis 0-based.- Throws:
IllegalStateException- when no series has been added yet
-
pointLabelHidden
Hide the label of one point while the rest of the series keeps its own (<c:dLbl><c:delete val="1"/>).pointIndexis 0-based. Hiding drops any caption set withpointLabel(int, java.lang.String).- Throws:
IllegalStateException- when no series has been added yet
-
view3D
Render the chart in 3-D with the given view angles (ECMA-376 §21.2.2.228view3D):rotXis the elevation androtYthe rotation, both in degrees;depthPercentis the depth as a percentage of the plot height (100 = default). The base type (bar/column/line/pie/area) becomes its*3DChartform on save. ImpliesthreeD(true).rotYanddepthPercentmust be non-negative; a negative value makesSheet.addChartthrowAxyraException. AdepthPercentof 0 keeps the default depth. -
plotAreaLayout
Position the inner plot area at an explicit rectangle in chart-relative fractions (ECMA-376 §21.2.2.88manualLayout):x/yare the top-left corner andw/hthe size, all in[0, 1]. Without this the plot area is laid out automatically. -
legendLayout
Position the legend at an explicit rectangle in chart-relative fractions (x/ytop-left,w/hsize, all in[0, 1]) — a manual legend layout. Without this the legend is placed automatically at itsposition. -
titleLayout
Position the chart title at an explicit rectangle in chart-relative fractions — a manual title layout. Without this the title is placed automatically.x/yare the top-left corner andw/hthe size, all in[0, 1]. -
trendline
Add a trendline to the most recently added series. Trendlines persist to the saved workbook per ECMA-376 §21.2.2.211.- Throws:
IllegalStateException- when no series has been added yetNullPointerException- iftrendlineis null
-
errorBars
Attach error bars to the most recently added series. Error bars persist to the saved workbook per ECMA-376 §21.2.2.55. Replaces any error bars set on that series before.- Throws:
IllegalStateException- when no series has been added yetNullPointerException- iferrorBarsis null
-
dataLabels
Attach data labels to the most recently added series. Data labels are re-emitted as<c:dLbls>on save (ECMA-376 §21.2.2.49) and read back viaChartView.seriesDataLabels(int). Anulllabelsremoves the labels set before. The label'sDataLabels.textColor()accepts only RGB colors; its alpha byte is ignored.- Throws:
IllegalStateException- when no series has been added yet, or the text color is a theme, indexed or automatic color
-
seriesType
The plot type of the most recently added series in a combo chart — the plot group it is drawn in (ECMA-376 Part 1 §21.2.2.145: a<c:barChart>,<c:lineChart>,<c:areaChart>or<c:scatterChart>under the one<c:plotArea>). A combo series given no type is a column series.Only a
combochart has more than one plot group;build()rejects a series type on any other chart.Each type is drawn against a kind of axis pair:
"column","line"and"area"against categories along the bottom and values up the side;"bar"(horizontal bars) against categories up the side and values along the bottom;"scatter"against a value axis on both edges. The series on one axis — the primary, or the secondary (secondaryAxis(boolean)) — must share one kind, so a combo mixes kinds only by putting one kind on each axis: columns with a scatter series on the secondary axis, bars with a line on the secondary axis.build()rejects any other mix.On the secondary axis a scatter series' Y values run up the right and its X values along the top; a bar series' values run along the top. A scatter series' X values are the
categoriesRefofseries(String, String, String), as on a scatter chart.- Parameters:
type-"column","line","area","bar"or"scatter"- Throws:
IllegalStateException- when no series has been added yetIllegalArgumentException- whentypeis none of those
-
secondaryAxis
Plot the most recently added series against a secondary value axis (on) — drawn on the right of the plot with its own scale, the way a ratio or a percentage is shown next to amounts — or against the primary one. On save the series goes in a plot group of its own type bound to the secondary axis pair (ECMA-376 Part 1 §21.2.2.226 valAx): values on the right for a column, line or area series, values along the top for a bar series, Y on the right and X along the top for a scatter series.Only a
combochart has a secondary axis;build()rejects one on any other chart, and a combo with every series on the secondary axis.- Throws:
IllegalStateException- when no series has been added yet
-
extendedApparatus
public Chart.Builder extendedApparatus(String chartExBase64, String colorsBase64, String styleBase64) Carry the byte-exact apparatus of a modern extended (cx:) chart — thechartExpart plus itschartColorStyle/chartStyleparts, each base64-encoded — so a re-authored waterfall/funnel/… re-emits the complete part set Excel requires to open the file. The structured builder fields (series/axes/…) cannot reconstruct an extended chart, and Excel refuses to open achartExthat lacks its colors/style relationships, so this is the faithful round-trip path. Obtain the arguments fromChartView.extendedChartExData()and its siblings. Passing anullchartExBase64is a no-op.Reference: ISO/IEC 29500 Transitional; MS extension namespace
.../office/drawing/2014/chartex. -
categoryAxisTitle
Sets the category (X) axis title;nullsets none. -
valueAxisTitle
Sets the value (Y) axis title;nullsets none. -
valueAxisScale
Fixes the value (Y) axis to the range[min, max]. Without this call the axis scales automatically. -
build
The immutable chart.- Throws:
IllegalStateException- when a series carries aseries typeor thesecondary axison a chart that is not a combo, when every series of a combo is on the secondary axis, or when series of two axis kinds (column/line/area, bar, scatter) share one axis
-