TX Sheet Control

ChartCollection.add Method

Method

Create a chart from cell data or series.

Owner: ChartCollection. Package: @txtextcontrol/tx-sheet-control-server. Version: 2.0.0.

Syntax

add(options: ChartObjectOptions): Chart

Parameters

ParameterTypeOptionalDescription
optionsChartObjectOptionsNoOptional settings validated before the operation is applied.

Return Value

Chart.

A detached result or a handle bound to the same worksheet.

Examples

Use a fresh sample workbook for this example. In the browser pass editor.workbook; in Node.js pass the server control. Document-bound objects are obtained from that same owner.

import type { ServerSheetControl } from '@txtextcontrol/tx-sheet-control-server';

function applyChartCollectionAdd(control: ServerSheetControl) {
    const book = control.workbook;
    const sheet = book.sheets.at(0);
    sheet.range('A1:B5').setValues([
        ['Region', 'Revenue'],
        ['North', 42000],
        ['South', 38500],
        ['East', 31200],
        ['West', 44900],
    ]);

    const chart = sheet.charts.add({
        type: 'column',
        dataRange: 'A1:B5',
        title: 'Revenue by region',
        anchor: { cell: 'F2' },
    });

    const chartCollection = sheet.charts;

    const result = chartCollection.add({
        anchor: { cell: 'F2' },
        size: { width: 640, height: 360 },
        title: 'Revenue by region',
        type: 'column',
        dataRange: 'A1:B5',
    });

    return result;
}

Remarks

Use this member on an object from the current document. Reacquire document-bound handles after replacement/deletion. Validate arguments against the declared types and documented bounds; handle exceptions or rejected promises.

See Also