Programmatically appends a BIFF8
chart sheet to the workbook, returning the new
TXLSWorksheet tab. Previously, chart sheets could only be preserved opaquely on a load-save round-trip via
TXLSCustomChart; this method writes a complete chart substream directly into
SaveAs(xlExcel97). Excel opens the result as a chart tab of the requested kind. Available since v2.41.0 (Roadmap #10 Phase 1); the array-of-series overload follows in v2.42.0, and later overloads add 3-D scenes and PivotChart links. The same series records are accepted by
TXLSWorksheet.AddChartObject for an embedded chart frame.
TXLSChartType enumeration
Selects the chart kind. Re-exported from lxHandle so user code does not need to import the chart-builder unit directly
type
TXLSChartType = (
xlsChartTypeColumn, xlsChartTypeBar, xlsChartTypeLine,
xlsChartTypePie, xlsChartTypeArea, xlsChartTypeScatter,
xlsChartTypeDoughnut,
xlsChartType3DColumn, xlsChartType3DBar, xlsChartType3DLine,
xlsChartType3DPie,
xlsChartTypeStackedColumn, xlsChartTypeStackedColumn100,
xlsChartTypeStackedBar, xlsChartTypeStackedBar100,
xlsChartTypeStackedLine, xlsChartTypeStackedLine100,
xlsChartTypeStackedArea, xlsChartTypeStackedArea100,
xlsChartTypeRadar, xlsChartTypeRadarFilled,
xlsChartTypeSurface, xlsChartTypeContour,
xlsChartTypeStockHLC, xlsChartTypeStockOHLC,
xlsChartTypeComboColumnLine);
The stacked variants set the clustered/stacked and 100% flags on the ordinary bar, line, or area record. Radar and filled radar use the Radar and RadarArea records; surface and contour share Surf and differ in the filled-surface flag. The stock kinds emit a line group with high-low lines, and the OHLC kind adds up/down bars. xlsChartTypeComboColumnLine places a column group on the primary axis and a line group on the secondary axis inside one chart substream. XlsChartTypeGrouping reports the grouping any chart type carries as a TXLSChartGrouping (xlsChartGroupClustered, xlsChartGroupStacked, xlsChartGroupPercentStacked); families without stacked bits always report clustered.
TXLSChartSeriesInfo record
Carries one series declaration. Categories and Values are A1-range strings (e.g. 'Sheet1!$B$2:$B$5'); a defined name or an external workbook reference is also compiled when the workbook engine can resolve it. The remaining fields activate optional records inside the Series block.
type
TXLSChartDataLabelsInfo = record
ShowValue, ShowPercent, ShowLabelAndPerc,
ShowLabel, ShowBubbleSizes, ShowSeriesName: Boolean;
end;
TXLSChartSeriesStyleInfo = record
HasLine: Boolean;
LineRgb: LongWord;
LineStyle: Word;
HasFill: Boolean;
FillRgb: LongWord;
HasFillTheme: Boolean;
FillThemeColor: Integer;
FillThemeTint: Double;
HasMarker: Boolean;
MarkerImk: Word;
MarkerRgbFore, MarkerRgbBack: LongWord;
MarkerSize: Word;
Explosion: Word;
end;
TXLSChartTrendlineInfo = record
Regt: Byte;
NOrder: Byte;
NumIntercept: Double;
FDispEq, FDispRSqr: Boolean;
NumForecast, NumBackcast: Double;
Name: WideString;
end;
TXLSChartErrorBarsInfo = record
Sertm: Byte;
Ebsrc: Byte;
FTeeTop: Boolean;
NumValue: Double;
Cnum: Word;
end;
TXLSChart3DInfo = record
Has3D: Boolean;
Rot: Word;
Elev: SmallInt;
Dist: Word;
Height, Depth, Gap: Word;
Perspective, Cluster, Autoscale, Scaling3D, Walls2D: Boolean;
Riser: Byte;
Taper: Byte;
end;
TXLSPivotChartInfo = record
HasPivot: Boolean;
SourceName: WideString;
HideCaptions: Boolean;
end;
TXLSChartSeriesInfo = record
Name: WideString;
Categories: WideString;
Values: WideString;
DataLabels: TXLSChartDataLabelsInfo;
HasDataLabels: Boolean;
SecondaryAxis: Boolean;
Style: TXLSChartSeriesStyleInfo;
HasStyle: Boolean;
Trendlines: array of TXLSChartTrendlineInfo;
ErrorBars: array of TXLSChartErrorBarsInfo;
end;
Series record fields
| Name | WideString. Literal legend caption for the series; an empty string lets Excel derive one from the source range. |
| Categories | WideString. A1 range, defined name, or resolvable external reference for the category values. |
| Values | WideString. A1 range, defined name, or resolvable external reference for the series values. |
| DataLabels | TXLSChartDataLabelsInfo. Per-series data-label switches; written as one AttachedLabel record when HasDataLabels is True. |
| HasDataLabels | Boolean. Enables DataLabels. |
| SecondaryAxis | Boolean. Binds the series to the secondary axis group; the builder emits the second axis pair when any series requests it. |
| Style | TXLSChartSeriesStyleInfo. Line, fill, marker, and pie-slice overrides; written when HasStyle is True. |
| HasStyle | Boolean. Enables Style. |
| Trendlines | Array of TXLSChartTrendlineInfo. Trendline declarations for the series. |
| ErrorBars | Array of TXLSChartErrorBarsInfo. Error-bar declarations; a Y pair normally uses two entries with Sertm 1 and 2. |
Data-label, style, trendline, and error-bar fields
TXLSChartDataLabelsInfo maps to the AttachedLabel grbit: ShowValue, ShowPercent, ShowLabelAndPerc, ShowLabel, ShowBubbleSizes, and ShowSeriesName each enable one label element.
TXLSChartSeriesStyleInfo uses BIFF LongRGB byte order. LineStyle is the lns value 0 (solid) through 5 (none). FillThemeColor follows the spreadsheet theme index order (0 light 1, 1 dark 1, 2 light 2, 3 dark 2, 4..9 accent 1..6, 10 hyperlink, 11 followed hyperlink) and FillThemeTint uses the DrawingML sign convention. MarkerImk is 0 none, 1 square, 2 diamond, 3 triangle, or 8 circle; MarkerSize is in points (2..72). Explosion is a pie or doughnut slice displacement percentage and 0 leaves the slice in place.
TXLSChartTrendlineInfo uses Regt 0 polynomial, 1 exponential, 2 logarithmic, 3 power, 4 moving average, or 5 linear. NOrder is the polynomial order or moving-average period. Pass a NaN NumIntercept for an automatic intercept, and use FDispEq / FDispRSqr to show the equation and R². NumForecast and NumBackcast are nonnegative period counts.
TXLSChartErrorBarsInfo uses Sertm 1 = Y+, 2 = Y−, 3 = X+, 4 = X−, and Ebsrc 1 = percent, 2 = fixed value, 3 = standard deviation, 4 = standard error, 5 = custom values. FTeeTop draws the end caps and NumValue is the magnitude for the non-custom sources; the builder forces Cnum to 0 unless Ebsrc is 5.
TXLSChart3DInfo carries Rot 0..360, Elev −90..90, Dist 0..100, Height / Depth 5..500 percent, and Gap 0..500. Riser is 0 rectangle or 1 ellipse; Taper is 0 none, 1 to a point, or 2 to the wider end. TXLSPivotChartInfo links the chart to a PivotTable view: SourceName names the view and HideCaptions maps to the hide-caption flag.
Syntax
Seven overloads cover progressively richer chart-sheet definitions:
// 1) v2.41.0 — name only; default column chart, no titles, no series.
function AddChartSheet(const Name: WideString): TXLSWorksheet;
// 2) v2.41.0 — name + chart type.
function AddChartSheet(
const Name : WideString;
ChartType : TXLSChartType): TXLSWorksheet;
// 3) v2.41.0 — + chart title.
function AddChartSheet(
const Name : WideString;
ChartType : TXLSChartType;
const Title: WideString): TXLSWorksheet;
// 4) v2.41.0 — + category-axis title + value-axis title.
function AddChartSheet(
const Name : WideString;
ChartType : TXLSChartType;
const Title : WideString;
const CatAxisTitle: WideString;
const ValAxisTitle: WideString): TXLSWorksheet;
// 5) v2.42.0 — + array of series (Name + Categories range + Values range).
function AddChartSheet(
const Name : WideString;
ChartType : TXLSChartType;
const Title : WideString;
const CatAxisTitle: WideString;
const ValAxisTitle: WideString;
const Series : array of TXLSChartSeriesInfo): TXLSWorksheet;
// 6) + a 3-D scene declaration.
function AddChartSheet(
const Name : WideString;
ChartType : TXLSChartType;
const Title : WideString;
const CatAxisTitle: WideString;
const ValAxisTitle: WideString;
const Series : array of TXLSChartSeriesInfo;
const A3D : TXLSChart3DInfo): TXLSWorksheet;
// 7) + a PivotChart link to an existing PivotTable view.
function AddChartSheet(
const Name : WideString;
ChartType : TXLSChartType;
const Title : WideString;
const CatAxisTitle: WideString;
const ValAxisTitle: WideString;
const Series : array of TXLSChartSeriesInfo;
const A3D : TXLSChart3DInfo;
const APivot : TXLSPivotChartInfo): TXLSWorksheet;
Remarks
For styled series, Series[i].Style.MarkerSize specifies the marker diameter in points; saving converts that diameter to the stored BIFF twip value. Each series retains its own formatting identity, while the inspected TXLSChartSeries.MarkerSize remains a raw-twip property and MarkerSizePoints exposes the equivalent point size
The emitted chart substream covers the BIFF8 framing the spec calls for — BOF (dt=$0020), Chart / PlotGrowth / Frame / Series / SheetProperties / AxesUsed / AxisParent (POS + category axis + value axis + PlotArea + Frame + ChartFormat + chart-kind record + ChartFormatLink + Legend), EOF. Existing chart-sheet round-trip via TXLSCustomChart is unchanged
Series formatting: HasStyle / Style emit the series line, fill, marker, and pie-slice overrides. HasDataLabels / DataLabels emit one AttachedLabel record for the series. SecondaryAxis binds the series to the secondary axis group and causes the second axis pair to be written. Trendlines and ErrorBars are copied through to the Series block in declaration order
3-D and PivotChart declarations: the two longest overloads take a TXLSChart3DInfo scene (rotation, elevation, perspective, height, depth, gap, riser, and taper) and a TXLSPivotChartInfo link (source PivotTable view name and hide-caption flag). The 3-D scene is written as Chart3d and the per-series shape as Chart3DBarShape; separate 2-D gap width and bar overlap remain builder defaults
Series name binding: each non-empty Series[i].Name is retained as a literal series caption. Excel uses this caption in the legend and series selector, and each series keeps its own formatting instead of inheriting the first series' marker settings
Series range binding (v2.47.0): starting in v2.47.0, the Categories and Values A1-range strings are compiled into real tArea3D cell-range references inside the BRAI, going through the formula compiler and the workbook EXTERNSHEET reference table. Before v2.47.0 these two fields were accepted on the API but emitted as cce=0 placeholders, so the rendered chart was empty. Existing v2.42.0 callers that left Categories / Values empty are unaffected
The returned TXLSWorksheet appears in the Sheets collection and gets a chart-sheet boundsheet entry written on save. Cell-level methods on the result are unsupported — the host worksheet is a chart container, not a data sheet
Example
This example builds a workbook with a data sheet and a column chart bound to two columns of that data sheet
var
Series: array of TXLSChartSeriesInfo;
begin
// Populate cells on Sheet1.
Workbook.Sheets[1].Name := 'Data';
// ... fill A1:B5 with categories + values ...
SetLength(Series, 1);
Series[0].Name := 'Quarterly Revenue';
Series[0].Categories := 'Data!$A$2:$A$5';
Series[0].Values := 'Data!$B$2:$B$5';
Workbook.Sheets.AddChartSheet(
'Revenue',
xlsChartTypeColumn,
'Quarterly Revenue',
'Quarter',
'USD',
Series);
Workbook.SaveAs('Revenue.xls', xlExcel97);
end;
Styled series example
This example adds data labels, a styled marker line, a linear trendline with an automatic intercept, and a second series on the secondary axis (include Math in the uses clause for NaN)
var
Series: array of TXLSChartSeriesInfo;
begin
SetLength(Series, 2);
Series[0].Name := 'Revenue';
Series[0].Categories := 'Data!$A$2:$A$5';
Series[0].Values := 'Data!$B$2:$B$5';
Series[0].HasDataLabels := True;
Series[0].DataLabels.ShowValue := True;
Series[0].HasStyle := True;
Series[0].Style.HasLine := True;
Series[0].Style.LineRgb := $00C0504D;
Series[0].Style.HasMarker := True;
Series[0].Style.MarkerImk := 8;
Series[0].Style.MarkerSize := 6;
SetLength(Series[0].Trendlines, 1);
Series[0].Trendlines[0].Regt := 5;
Series[0].Trendlines[0].NumIntercept := NaN;
Series[0].Trendlines[0].FDispEq := True;
Series[1].Name := 'Margin';
Series[1].Categories := 'Data!$A$2:$A$5';
Series[1].Values := 'Data!$C$2:$C$5';
Series[1].SecondaryAxis := True;
Workbook.Sheets.AddChartSheet(
'Revenue and margin', xlsChartTypeLine,
'Revenue', 'Quarter', 'USD', Series);
end;
Limitations
Per-chart-type formatting details that the records do not carry (2-D gap width, bar overlap, pie hole size, first-slice angle, and independent trendline or error-bar paint) are still emitted at the chart-builder defaults. Series line/fill/marker settings, data labels, secondary-axis binding, trendlines, error bars, 3-D scene parameters, and PivotChart links are exposed through the records above. Save-and-reopen with Excel preserves the chart sheet's presence, kind, title, axis titles, series captions, and (from v2.47.0) the series data binding
See also