Pivot Charts
Register the PivotTable and chart dependencies first, then add the two plugins below before creating the workbook. Merge the UI locale into your locales configuration and load the corresponding stylesheet. A Pro license is required.
pnpm add @univerjs-pro/sheets-pivot-chart @univerjs-pro/sheets-pivot-chart-uinpm install @univerjs-pro/sheets-pivot-chart @univerjs-pro/sheets-pivot-chart-uiyarn add @univerjs-pro/sheets-pivot-chart @univerjs-pro/sheets-pivot-chart-uibun add @univerjs-pro/sheets-pivot-chart @univerjs-pro/sheets-pivot-chart-uiimport { UniverSheetsPivotChartPlugin } from '@univerjs-pro/sheets-pivot-chart'import { UniverSheetsPivotChartUIPlugin } from '@univerjs-pro/sheets-pivot-chart-ui'import SheetsPivotChartLocale from '@univerjs-pro/sheets-pivot-chart-ui/locale/en-US'import { LocaleType } from '@univerjs/core'import '@univerjs-pro/sheets-pivot-chart/facade'import '@univerjs-pro/sheets-pivot-chart-ui/lib/index.css'univerAPI.loadLocales(LocaleType.EN_US, SheetsPivotChartLocale)univer.registerPlugin(UniverSheetsPivotChartPlugin)univer.registerPlugin(UniverSheetsPivotChartUIPlugin)The advanced Sheets preset already includes both plugins. Use it together with the core and drawing presets, and import @univerjs-pro/sheets-pivot-chart/facade explicitly for the APIs on this page.
Configure the worker
Preset configuration
These options belong to UniverSheetsAdvancedPreset:
useWorkerbooleanDefault:falseEnable the advanced features in the formula Worker.
If you use a Worker, pass UniverSheetsAdvancedPreset({ useWorker: true }) on the main thread and UniverSheetsAdvancedWorkerPreset() inside the Worker. Plugin-mode details are in the package reference.
Independent report
An independent chart owns its report. After insertion, add a row field and a value field. The example uses the first two source columns.
const workbook = univerAPI.getActiveWorkbook()const sheet = workbook?.getActiveSheet()if (!sheet) throw new Error('No active worksheet')sheet.getRange('A1:B4').setValues([ ['Region', 'Sales'], ['East', 100], ['West', 200], ['East', 50],])const chart = await sheet.insertPivotChart( sheet.newPivotChart(univerAPI.Enum.ChartTypeString.Column) .setSource('A1:B4').setPosition('D2').setSize(640, 360).build(),)const fields = chart.getSourceFieldsInfo()await chart.addField(fields[0].id, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0)await chart.addField(fields[1].id, univerAPI.Enum.PivotTableFiledAreaEnum.Value, 0)Link to a PivotTable
Field, filter, sort, and collapse edits are shared with the referenced PivotTable and with its other linked charts, while appearance and position remain independent. Removing the chart does not remove the table; removing the table makes the chart unavailable until the same table is restored.
const pivotTable = workbook.getPivotTableById('pivot-table-1')if (!pivotTable) throw new Error('PivotTable not found')const linkedChart = await sheet.insertPivotChart( pivotTable.newChart(univerAPI.Enum.ChartTypeString.Line).setPosition('D22').build(),)linkedChart.setFieldButtonsVisible(true).setExpandCollapseButtonsVisible(true)Supported chart types
Line, column, bar, area, pie, doughnut, and combination charts are supported, including stacked variants where available. Scatter, bubble, radar, and waterfall are not supported. Pie uses the first value series; doughnut retains multiple series. Subtotals and grand totals are excluded from chart categories.
See FSheetPivotChart for the field, filter, style, and lifecycle APIs.
Copy and delete worksheets
Copying a worksheet also copies its PivotCharts and assigns them new IDs. An independent report whose source is on the copied sheet uses the new sheet and an independent cache. A linked chart follows the copied PivotTable when that table is copied with the sheet, and references to other sheets remain unchanged. Deleting a worksheet removes its PivotCharts and the resources associated with them; undo restores their definitions and source data.
Report filters
getOptions(), setOptions({ allowMultipleFilters: true }), and setDateFilter(fieldId, condition) act on the chart's authoritative report. On a linked chart they update the PivotTable and its other linked charts; on an independent chart they update only that chart's report. Omit condition to clear only the date condition. For date serials and whole-day comparisons, see multiple filters and date conditions.
How is this guide?