Dokumentacja HotXLS

Metoda AddChartSheet

Dodaje nowy arkusz wykresu na koniec kolekcji arkuszy i zwraca nowy obiekt TXLSChartSheet

Składnia

function AddChartSheet: TXLSChartSheet; overload;
type
  TXLSChartType = (
    xlsChartTypeColumn,
    xlsChartTypeBar,
    xlsChartTypeLine,
    xlsChartTypePie);

Uwagi

function AddChartSheet(AName: WideString): TXLSChartSheet; overload;
type
  TXLSChartSeriesInfo = record
    Name        : WideString;
    Categories  : WideString;
    Values      : WideString;
  end;

Przykład

Metoda tworzy wpis arkusza wykresu w kolekcji Arkuszy, jak ujawnia to zakładka w Excelu. Typ arkusza jest rejestrowany jako arkusz wykresu w metadanych skoroszytu. Zwrócony obiekt TXLSChartSheet obsługuje właściwości Chart (serializacja wykresu BIFF8), Name, Visible i Index. Nie zwraca TXLSWorksheet ponieważ arkusze wykresów nie mają komórek arkusza
// 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;

Zobacz też

Ten przykład wstawia nowy arkusz wykresu o nazwie "Wykres Sprzedaży"


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

Przykład

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;

Limitations

Per-chart-type formatting details (gap width, bar overlap, pie hole size, marker style) are still emitted at the chart-builder defaults — not yet exposed on the API. 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

Zobacz także