TX Sheet Control

ChartSeries.dataLabels Property

Property

Formats the original series values displayed on chart marks, including percentage-stacked charts. Labels do not change the numeric series.

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

Syntax

dataLabels?: ChartSeries['dataLabels']

Settings

numberFormatCode is an Excel numeric format of at most 255 characters. color is a six-digit RGB caption color; fontSize uses points (1–200); bold is a Boolean. position is center, insideEnd or outsideEnd. Enable chart elements.dataLabels to display captions. Omitted fields inherit chart defaults. A 100% stacked chart positions bars by normalized values but displays original values with this format.

Examples

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

function configureReport(control: ServerSheetControl) {
    const book = control.workbook;
    const sheet = book.sheets.at(0);
    const chart = sheet.charts.add({
        type: 'bar-100', title: 'Event budget',
        series: [
            { name: 'Income', values: { values: [1936, 1831] }, categories: { values: ['Estimated', 'Actual'] },
              color: '#ff4500', dataLabels: { numberFormatCode: '"$"#,##0', color: '#ffffff', bold: true, position: 'center' } },
            { name: 'Expenses', values: { values: [882, 333] }, categories: { values: ['Estimated', 'Actual'] },
              color: '#ffb499', dataLabels: { numberFormatCode: '"$"#,##0', position: 'center' } }
        ], anchor: { cell: 'E2' }, size: { width: 520, height: 320 }
    });
    chart.update({
        elements: { dataLabels: true, gridlines: false },
        presentation: {
            backgroundColor: null, borderColor: null,
            plotLayout: { x: 0.12, y: 0.24, width: 0.85, height: 0.68 },
            categoryAxis: { visible: true, lineVisible: false, labelRotation: -90 },
            valueAxis: { visible: false }, gapWidth: 50
        }
    });
    return chart;
}