Charts
Charts render worksheet data as a chart. The chart model and UI packages provide the feature.
Plugin mode
pnpm add @univerjs-pro/chart-ui @univerjs-pro/sheets-chart @univerjs-pro/sheets-chart-uinpm install @univerjs-pro/chart-ui @univerjs-pro/sheets-chart @univerjs-pro/sheets-chart-uiyarn add @univerjs-pro/chart-ui @univerjs-pro/sheets-chart @univerjs-pro/sheets-chart-uibun add @univerjs-pro/chart-ui @univerjs-pro/sheets-chart @univerjs-pro/sheets-chart-uiimport ChartUIEnUS from '@univerjs-pro/chart-ui/locale/en-US'import { UniverSheetsChartPlugin } from '@univerjs-pro/sheets-chart'import { UniverSheetsChartUIPlugin } from '@univerjs-pro/sheets-chart-ui'import SheetsChartUIEnUS from '@univerjs-pro/sheets-chart-ui/locale/en-US'import SheetsChartEnUS from '@univerjs-pro/sheets-chart/locale/en-US'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import '@univerjs-pro/chart-ui/facade'import '@univerjs-pro/sheets-chart/facade'import '@univerjs-pro/chart-ui/lib/index.css'import '@univerjs-pro/sheets-chart-ui/lib/index.css'const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales(ChartUIEnUS, SheetsChartEnUS, SheetsChartUIEnUS), },})univer.registerPlugin(UniverSheetsChartPlugin)univer.registerPlugin(UniverSheetsChartUIPlugin)Mobile support
Configure the mobile editor first. In the plugin-mode setup on this page, replace the desktop registrations below with the mobile exports from the same packages, and do so before opening a document. Keep the model plugins, styles, locales, and Facade imports, and do not register both variants.
| Package | Desktop registration | Mobile registration |
|---|---|---|
@univerjs-pro/sheets-chart-ui | UniverSheetsChartUIPlugin | UniverSheetsChartMobileUIPlugin |
Preset mode
@univerjs/preset-sheets-advanced already includes the chart feature, but it requires the drawing preset at runtime.
pnpm add @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advancednpm install @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advancedyarn add @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advancedbun add @univerjs/preset-sheets-drawing @univerjs/preset-sheets-advancedimport { UniverSheetsAdvancedPreset } from '@univerjs/preset-sheets-advanced'import UniverPresetSheetsAdvancedEnUS from '@univerjs/preset-sheets-advanced/locales/en-US'import { UniverSheetsCorePreset } from '@univerjs/preset-sheets-core'import UniverPresetSheetsCoreEnUS from '@univerjs/preset-sheets-core/locales/en-US'import { UniverSheetsDrawingPreset } from '@univerjs/preset-sheets-drawing'import UniverPresetSheetsDrawingEnUS from '@univerjs/preset-sheets-drawing/locales/en-US'import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'import '@univerjs/preset-sheets-advanced/lib/index.css'import '@univerjs/preset-sheets-core/lib/index.css'import '@univerjs/preset-sheets-drawing/lib/index.css'const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( UniverPresetSheetsCoreEnUS, UniverPresetSheetsDrawingEnUS, UniverPresetSheetsAdvancedEnUS, ), }, presets: [UniverSheetsCorePreset(), UniverSheetsDrawingPreset(), UniverSheetsAdvancedPreset()],})Create and update charts
worksheet.newChart(type) returns a detached builder. Nothing is added to the worksheet until the chart information is built and passed to worksheet.insertChart(info).
const workbook = univerAPI.getActiveWorkbook()if (!workbook) throw new Error('No active workbook')const worksheet = workbook.getActiveSheet()const info = worksheet .newChart(univerAPI.Enum.ChartTypeString.Column) .setSource({ range: 'A1:D6', orientation: univerAPI.Enum.ChartSourceOrientation.Columns, }) .setPosition('F2') .setSize(640, 360) .setCategoryField(0) .setValueFields([1, 2, 3]) .setTitle('Quarterly revenue') .build()const chart = await worksheet.insertChart(info)chart.setLegend({ visible: true }).bringToFront()const updatedInfo = chart.toBuilder(univerAPI.Enum.ChartTypeString.Line).setSubtitle('FY 2026').build()await chart.update(updatedInfo)const svg = await chart.exportImage({ format: 'svg' })Calling a setter on an inserted chart updates it immediately. Use toBuilder(type) with update(info) to obtain a fully detached copy or to change the chart type. exportImage() returns undefined when no UI renderer can produce an image.
worksheet.getCharts() and worksheet.getChart(id) return live charts. Call await chart.remove() to delete a chart. Register shared ECharts themes with univerAPI.registerTheme(name, theme).
Chart sheets
insertChartSheet() gives a chart its own tab. The chart builder must reference a grid sheet in the same workbook, and the source cells remain on that sheet.
import '@univerjs-pro/sheets-chart/facade'const workbook = univerAPI.getActiveWorkbook()const data = workbook?.getSheetByName('Data')if (!workbook || !data) throw new Error('The Data sheet is required')const info = data .newChart(univerAPI.Enum.ChartTypeString.Column) .setSource({ sheetId: data.getSheetId(), range: 'A1:B4' }) .build()const chartSheet = await workbook.insertChartSheet(info, { name: 'Sales' })const primaryChart = chartSheet.getPrimaryChart()await chart.moveTo(targetSheet) moves an existing chart. A chart moved into a chart sheet becomes an additional chart on that sheet. Moving the primary chart out of a chart sheet requires a tab that contains nothing else, and the move removes that tab. Moves can be undone and redone. The primary chart's context menu opens the chart panel, copies the chart, and exports an image, but it has no Delete action.
FWorkbook.insertChartSheet() · FWorksheet.getPrimaryChart()
Error bars
setErrorBars() can be called on a builder or on a live chart. Basic 2D column, bar, line, and scatter charts support error bars. seriesIndex is zero-based and counts the category field in the source data. Columns and lines use y, bars use x, and scatter charts can use either numeric axis.
chart.setErrorBars([ { seriesIndex: 1, direction: 'y', type: 'both', valueType: 'percentage', value: 20 },])Multi-level category axes
When adjacent source columns form a hierarchy, pass their zero-based indexes to setCategoryFields() in root-to-leaf order, and then enable the multi-level axis.
const info = worksheet .newChart(univerAPI.Enum.ChartTypeString.Column) .setSource({ range: 'A1:D7', orientation: univerAPI.Enum.ChartSourceOrientation.Columns, }) .setCategoryFields([0, 1]) .setMultiLevelCategoryAxis(true) .setValueFields([2, 3]) .setPosition('F2') .build()const chart = await worksheet.insertChart(info)chart.setCategoryFields([0, 1]).setMultiLevelCategoryAxis(true)clearCategoryFields() removes the ordered mapping. setMultiLevelCategoryAxis(false) keeps the selected fields and disables only hierarchical rendering.
Radar charts
Radar charts accept setShape() with univerAPI.Enum.ChartRadarShape.Polygon (the default) or univerAPI.Enum.ChartRadarShape.Circle, and setFill(true) to fill each series area. Without fill, only the outlines are drawn. setRadarAxisLabel({ visible, color, fontSize, bold, italic, family, format }) styles the numeric scale labels, and resetRadarAxisLabel() restores the defaults. Scale labels are visible by default, and the scale is divided into five intervals. Radar lines take their color, width, and dash style from the series border, and the area fill takes the series color and fill opacity.
const info = worksheet .newChart(univerAPI.Enum.ChartTypeString.Radar) .setSource('A1:C6') .setCategoryField(0) .setValueFields([1, 2]) .setShape(univerAPI.Enum.ChartRadarShape.Circle) .setFill(true) .setRadarAxisLabel({ visible: true, fontSize: 12, bold: true }) .build()await worksheet.insertChart(info)FRadarChartBuilder.setRadarAxisLabel()
Supported chart types
univerAPI.Enum.ChartTypeString provides the following types: Line, LineStacked, LinePercentStacked, Column, ColumnStacked, ColumnPercentStacked, Bar, BarStacked, BarPercentStacked, Pie, Donut, Area, AreaStacked, AreaPercentStacked, Radar, Scatter, Combination, WordCloud, Funnel, Bubble, Relation, Waterfall, Pareto, Sankey, Heatmap, Boxplot, Candlestick, Histogram, Treemap, Sunburst, Gauge, and Chord.
The Chart Facade reference documents the shared builder configuration API.
LineStacked and LinePercentStacked are standalone 2D chart types. Before using them in a server renderer or in Office file conversion, verify that the target supports them.
Hidden data and independent categories
setPlotVisibleOnly(false) includes values from hidden rows and columns, and getPlotVisibleOnly() reads the current setting. For sources with separate category columns, setSeriesToCategory() maps each value-field index to its category-field indexes. The indexes refer to the physical source vectors, not to the series that remain after filtering. Entries that are left out inherit the shared categories, and {} clears the overrides.
With columns A:D, for example, the value series in D can use C as its category, while B keeps the shared category in A.
const chart = worksheet.getCharts()[0]if (!chart) throw new Error('No chart')chart.setPlotVisibleOnly(false)chart.setSeriesToCategory({ 3: [2] })For aggregated interactive reports, see PivotCharts.
3D charts
3D charts use the same plugin registration. Select a 3D chart type, and then configure the view on its detached builder.
The supported types are Line3D, Column3D, ColumnStacked3D, ColumnPercentStacked3D, Bar3D, BarStacked3D, BarPercentStacked3D, Pie3D, Area3D, AreaStacked3D, and AreaPercentStacked3D.
const info = worksheet .newChart(univerAPI.Enum.ChartTypeString.Column3D) .setSource('A1:C5') .setCategoryField(0) .setValueFields([1, 2]) .setPosition('F18') .setSize(640, 360) .setThreeD({ view: { rotX: 20, rotY: 30, rightAngleAxes: false, perspective: 30 }, gapDepth: 120, }) .build()await worksheet.insertChart(info)perspective applies to axis-based charts only when rightAngleAxes is false. clearThreeD() clears the configured view settings but keeps the 3D chart type and the depth axis; use clearDepthAxis() to clear the depth axis. 3D axis charts expose no secondary axes or trendlines, and Pie3D draws a solid pie.
Logarithmic value axes
Supported 2D line, area, column, bar, and combination charts accept scaleType: 'log' on the numeric axis. Use setYAxis() for vertical value axes and setXAxis() for the horizontal numeric axis of a bar chart. setRightYAxis() configures an existing secondary numeric axis.
The default base is 10. A custom logBase must be finite and between 2 and 1000; fractional values such as 2.5 are allowed. Numeric bounds must be positive. Zero and negative data points are omitted from the logarithmic plot, but the source data is unchanged. Percent-stacked and 3D charts do not support logarithmic axes.
const info = worksheet .newChart(univerAPI.Enum.ChartTypeString.Line) .setSource('A1:B5') .setYAxis({ scaleType: 'log', logBase: 10 }) .setPosition('F36') .setSize(640, 360) .build()const chart = await worksheet.insertChart(info)await chart.update( chart.toBuilder(univerAPI.Enum.ChartTypeString.Line) .setYAxis({ scaleType: 'linear' }) .build(),)To insert a new chart, build it and then insert it; to apply a detached update, use await chart.update(builder.build()). Setting scaleType: 'linear' removes the logarithm base, and axis patches that do not touch the scale preserve it.
How is this guide?