# Charts and Sparklines

> Add column, line and other charts to a worksheet with ChartCollection.add or the Insert tab, edit them with Chart Design and create sparkline groups in cells.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Spreadsheet Documents > Charts and Sparklines
- **2492 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/charts/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/charts/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/spreadsheets/charts/llms-full.txt

---

A worksheet chart belongs to its worksheet and visualizes a source range or supported explicit series, such as revenue by region. Sparklines show compact trends inside cells. Charts on a dashboard are a different thing: you configure them separately, as widgets.

### Create a Chart in Code

The following code writes the revenue of four regions into the first worksheet and adds a column chart next to it. `editor` is the [Spreadsheet](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/spreadsheet/llms-full.txt) of the browser editor:

```javascript
const sheet = editor.workbook.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: 'D2' }, size: { width: 640, height: 360 }
});

editor.ui.selectChart(chart);
```

The code works as follows:

- [Worksheet.range](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/range-method/llms-full.txt) and [Range.setValues](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/range/setvalues-method/llms-full.txt) write the column headings `Region` and `Revenue` and one row for each region into `A1:B5`.
- [Worksheet.charts](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/charts-property/llms-full.txt) returns the [ChartCollection](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/chartcollection/llms-full.txt) of the worksheet. Its [add](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/chartcollection/add-method/llms-full.txt) method creates a chart from the cell data: a column chart over `A1:B5` with the title `Revenue by region`, anchored at cell `D2` and 640 by 360 pixels in size.
- [EditorUi.selectChart](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/editorui/selectchart-method/llms-full.txt), reached through `editor.ui`, selects the new chart in the editor.

Chart dimensions and offsets are unscaled CSS pixels. Moving or resizing the browser host does not redefine these document coordinates.

Use the chart handle, a [ChartHandle](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/charthandle/llms-full.txt), to rename, move, resize, update and remove the chart, for example with its methods [moveTo](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/charthandle/moveto-method/llms-full.txt), [resize](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/charthandle/resize-method/llms-full.txt), [update](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/charthandle/update-method/llms-full.txt) and [remove](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/charthandle/remove-method/llms-full.txt). Its lifetime follows the owning worksheet and document.

### Create and Edit a Chart in the UI

![The Sales Summary worksheet with a revenue-by-region column chart over the Region and Revenue columns, selected so that the Chart Design tab shows its chart styles and the Select Data and Change Chart Type commands](https://docs.textcontrol.com/assets/img/tx-sheet-control/worksheet-chart.9e4c6a09.webp)

1. Select the category and value range.
2. Choose a chart from the **Insert** tab.
3. Review the preview before you confirm.

Right-click a chart to open its context menu. **Colors…** and **Filter Data…** open panels beside the chosen command, kept within the browser window. **Select Data…** opens the chart editor, and the ellipsis beside **Axis Titles** opens the axis-title dialog.

To edit an existing chart, select it and use **Chart Design → Select Data** or **Change Chart Type**:

![The Format Chart dialog with the chart family and variant selection, a live preview of Revenue by region and the Title, Data Range, Series In and Legend settings](https://docs.textcontrol.com/assets/img/tx-sheet-control/chart-type-dialog.4a89c8ea.webp)

- **Region comparisons.** The first column supplies the region labels, and the Revenue column supplies one numeric series.
- **Time trends.** Choose a line variant and an ordered month series.

[Chart Dialogs](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/chart-dialogs/llms-full.txt) explains Title, Data Range, Series In and Legend, and how to review a draft without replacing the current chart.

### Choose Types and Series

For the actual names of the supported types and styles, use the exported inventories [CHART\_TYPES](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/chart-types-constant/llms-full.txt) and [CHART\_STYLES](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/chart-styles-constant/llms-full.txt) and the [ChartObjectOptions](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/chartobjectoptions/llms-full.txt) reference. The series orientation, the headers and the categories must match the layout of the source. Test labels, negative values, empty data and mixed types.

Selecting a chart exposes contextual design and format commands. Give charts meaningful titles and labels, and use colors with sufficient contrast. A visually attractive chart can still be misleading if the source aggregation or the category definition is wrong.

### Add Sparklines

Sparklines provide compact trends at the level of a cell. Supported worksheet and workbook APIs create and update sparkline groups from a data range and a destination range: [Worksheet.addSparklines](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/addsparklines-method/llms-full.txt) and [Worksheet.updateSparklineGroup](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/updatesparklinegroup-method/llms-full.txt), or [Workbook.addSparklines](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/workbook/addsparklines-method/llms-full.txt) and [Workbook.updateSparklineGroup](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/workbook/updatesparklinegroup-method/llms-full.txt) for the active sheet.

In the editor, select the destination cells and choose **Insert → Sparklines**, then a sparkline type. The **Create Sparklines** dialog groups its controls into **Data & Location**, **Appearance** and **Display**. Set the source and destination ranges first, then inspect the actual miniature charts in **Live Preview**. Opening a section closes the previous section; switches for markers, negative points, the axis and shared scaling keep the dialog frame stable.

![Create Sparklines with Display switches and three live column-sparkline previews](https://docs.textcontrol.com/assets/img/tx-sheet-control/sparkline-dialog.9d0d6e70.webp)

Choose **OK** to create the group or **Cancel** to discard the draft. The preview does not create sparkline groups in the worksheet.

Keep the dimensions of the source and the location compatible. Clear sparklines with [Worksheet.clearSparklines](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/browser/worksheet/clearsparklines-method/llms-full.txt) without assuming that the underlying source values are deleted.

### Save and Export Charts

Charts and sparklines participate in supported XLSX and TXWB persistence and in PDF rendering. Review specialized chart features of imported files with [XLSX Compatibility](https://docs.textcontrol.com/tx-sheet-control/document-processing/xlsx-compatibility/llms-full.txt).

### Native Chart Presentation

Chart presentation includes transparent surfaces, manual plot and legend placement, independent category and value axes, rotated category captions, numeric axis formats and bar gaps. Value labels on 100% stacked charts display the original series values.

```javascript
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
    }
});
```

### Next Steps

- [Chart Dialogs](https://docs.textcontrol.com/tx-sheet-control/spreadsheet-editor/chart-dialogs/llms-full.txt): choose a chart family and variant and set the title, data range, series and legend.
- [Widgets](https://docs.textcontrol.com/tx-sheet-control/dashboards/widgets/llms-full.txt): add aggregated charts and interactive filters to a dashboard.
- [XLSX Compatibility](https://docs.textcontrol.com/tx-sheet-control/document-processing/xlsx-compatibility/llms-full.txt): check how imported chart features survive the exchange with Excel.

---

## Nearby

- **Previous:** [Data Validation](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/validation/llms-full.txt)
- **Next:** [Pictures and Shapes](https://docs.textcontrol.com/tx-sheet-control/spreadsheets/pictures-shapes/llms-full.txt)
