Introducing a new way to review your PRs.

Read the announcement

frappe / frappe-ui

The all-in-one toolkit for modern frontends. High-quality components, app recipes and AI-ready docs.

View on GitHub

28 documents · Updated Nov 23, 2026

docs / charting

Charting system

The charting system is the shared visual language for data in Frappe applications. It turns flat data rows and column names into readable visual analytics while keeping data meaning, number display, color, layout, interaction, and chart states consistent across chart types. Its public package also exposes the shared chart frame, legend, tooltip, theme tokens, and chart lifecycle for custom plots.

System purpose

Chart family

The chart family provides one public entry point at src/…/index.ts. It supports eleven chart components for axis trends and comparisons, part-to-whole views, process drop-off, grid values, calendar activity, flows, and single-number readings. The same entry point also exposes the shared chart frame and theme helpers, so a custom plot can use the same surrounding behavior as a built-in chart.

The chart components describe what a data column means. They do not ask application code to manage renderer-specific settings for common chart needs. See Chart components and types for the component-level contract and type-specific behavior.

References: src/…/index.ts• L1-42 src/…/types.ts• L694-907 src/…/Overview.md• L3-20

Visual analytics boundary

The library draws data that the application has already shaped. The application supplies rows, column keys, and any domain calculations such as a comparison value. The chart family then provides a visual reading of those values without modeling the application domain.

This boundary keeps saved or serialized chart settings simple. A chart can name the columns it needs and can be rebuilt from the same flat props when the query or screen changes.

References: src/…/types.ts• L694-746 spec/charts.md• L23-43 spec/…/0015-what-enters-charts.md• L120-126

Data normalization

Data shapes

The axis charts accept two common row shapes. Wide data names several value columns in y, while long data names one value column in y and a grouping column in splitBy. Both shapes become the same internal series model before rendering.

Other chart families use the shape that matches their visual question. A donut and a percentage bar read category and value columns, a heatmap reads two category columns and one value column, and a calendar heatmap reads one date and one value per row. A scatter reads two measures with an optional size and group, while a Sankey reads source, target, and flow value columns. A funnel reads ordered stages, while a number card reads one value with an optional comparison and trend.

The following flow shows the shared boundary between application data, normalized readings, and the parts that consume those readings.

flowchart LR
    Rows[Application data rows] --> Shape[Flat chart props]
    Shape --> Normalize[Shared normalization]
    Normalize --> Model[Series, slices, cells, points, or links]
    Model --> Option[Renderer option]
    Model --> Chrome[Legend, tooltip, labels, and states]
    Model --> Events[Selection and keyboard events]

References: src/…/types.ts• L126-179 src/…/types.ts• L181-213 src/…/types.ts• L303-332 src/…/types.ts• L421-510 src/…/seriesData.ts• L31-86 src/…/Overview.md• L22-27

Normalized readings

Normalization makes one shared reading for each chart. The plot, legend, tooltip, labels, keyboard cursor, and selection event use that reading rather than each interpreting the raw rows again. This prevents a visible mark from disagreeing with the value shown beside it.

Normalization also applies shared data rules. Long axis data is pivoted by its category and group, missing combinations remain missing, and an optional series cap keeps the largest groups and sums the tail under the reserved Others identity. Secondary-axis columns and tooltip-only columns are carried by category during this pivot, so they do not become extra grouped series. Category order follows the data order unless a chart needs a numeric scale, in which case the plotted rows follow that scale. Breakdown rows use stable identities across the donut and percentage bar, while calendar rows become date-keyed cells.

References: src/…/seriesData.ts• L47-143 src/…/seriesData.ts• L223-332 src/…/axisChartCommon.ts• L236-295 src/…/scatterOptions.ts• L55-113 src/…/slices.ts• L43-86 src/…/calendarHeatmapOptions.ts• L271-353

Breakdown readings

The donut and percentage bar share one breakdown model. It groups valid category values, keeps the largest entries when a slice cap applies, and places the remaining values in Others. The model also owns visible shares, colors, legend entries, tooltip values, and selection rows, so changing the display form does not change the reading.

Hiding a part recalculates the visible total while keeping the part identity and palette position stable. A zero or invalid part does not create a drawable mark, so a breakdown with no drawable parts enters the empty state.

References: src/…/slices.ts• L15-29 src/…/slices.ts• L43-86 src/…/slices.ts• L114-157 src/…/PercentageBarChart.vue• L132-147 src/…/types.ts• L1113-1151

Calendar readings

The calendar heatmap turns dated rows into a complete day grid across the requested range. It preserves days with no row as visible empty days, assigns values to a shared continuous color scale, and groups long ranges into aligned yearly bands. The plot, scale, tooltip, and keyboard reading use the same calendar grid.

Date-only strings are read as calendar dates rather than shifted instants. Duplicate rows for one day resolve to the last row, while development mode warns that the input should be pre-aggregated when another rule is needed.

References: src/…/calendarHeatmapOptions.ts• L117-139 src/…/calendarHeatmapOptions.ts• L186-239 src/…/calendarHeatmapOptions.ts• L271-353 src/…/CalendarHeatmapChart.vue• L120-174 src/…/types.ts• L1202-1243

Missing readings

Missing values retain their meaning instead of being changed to zero. A missing value leaves a line gap, a missing heatmap value leaves its category in the grid without drawing a cell, and a point without both coordinates is not plotted. A calendar day without a row remains an empty day rather than a zero-valued data cell. Invalid flow or part values are excluded when the visual form cannot represent them.

The chart reports recoverable configuration problems in the chart error state or with development warnings. This keeps a bad data point from silently becoming a different business reading.

References: src/…/seriesData.ts• L283-289 src/…/scatterOptions.ts• L71-95 src/…/calendarHeatmapOptions.ts• L321-348 src/…/useAxisChart.ts• L89-146 src/…/States.md• L8-13 src/…/SankeyChart.md• L25-30

Option construction

Declarative chart meaning

Chart props state the reading that the user should get from the data. Axis type, stacking, series mark, value axis, reference line, palette, and display format are all part of that reading. The component chosen by the caller supplies the default mark, while per-series settings can change the mark, label, color, or line style so a mixed chart does not need a separate chart concept.

The option builders translate this meaning into the renderer’s option shape. Shared axis rules, series colors, value scales, reference lines, and mark styles are built from the normalized model. This gives bar, line, and area charts one common behavior even when their visual marks differ. A horizontal bar changes which side carries the category axis, while a dual-axis chart keeps each measure on its named scale.

References: src/…/types.ts• L67-212 src/…/axisChartOptions.ts• L91-187 src/…/axisChartOptions.ts• L348-359 src/…/BarChart.md• L77-94

Stacked readings

Stacking changes the relationship between series without changing their source rows. Bars and areas can share a stack, while lines remain independent. A normalized stack changes the plot to a 0–100 share reading but keeps the original measure for the tooltip and selection event.

The share is calculated from the visible stack. This means a legend action changes the part-to-whole reading while the row behind each mark remains the caller’s original data.

References: src/…/axisChartOptions.ts• L216-345 src/…/types.ts• L195-212 src/…/AreaChart.md• L7-22

Reference annotations

Reference lines provide fixed targets, thresholds, or change points without becoming data series. They use the value axis that they name and remain outside the legend, hidden-series state, tooltip rows, and bar spacing.

The option builder groups annotations by their target axis and gives them a quiet host layer above the plotted marks. On a scatter or numeric x-axis, an x reference is a numeric position rather than a category.

References: src/…/referenceLines.ts• L82-126 src/…/referenceLines.ts• L128-186 src/…/axisChartOptions.ts• L171-186 src/…/types.ts• L121-165

Renderer overrides

echartOptions is the escape hatch for a renderer option that the chart contract does not name. The library first builds the normal option and then applies the override at the chart, axis, or series boundary. Nested objects merge, while arrays replace as a whole so a partial array cannot create an unclear option.

Common data meaning stays in typed props. The override is for renderer-specific behavior, not a second path for a feature that belongs in the shared chart model.

References: src/…/types.ts• L22-30 src/…/types.ts• L745-746 src/…/axisChartOptions.ts• L348-359 src/…/axisChartOptions.ts• L590-592 src/…/utils.ts• L12-38 src/…/Overview.md• L162-170

Shared chart context

Option construction receives the values that must stay aligned across plot and chrome. These include resolved colors, hidden series, measured plot width, and format functions. A builder can therefore produce a plot that uses the same series order, axis range, and display rules as the tooltip, legend, keyboard cursor, and selection event.

Reference lines remain annotations rather than data series. They are kept outside the normal series list so they do not change the legend, hidden-series state, tooltip rows, or bar spacing.

References: src/…/axisChartCommon.ts• L26-31 src/…/useAxisChart.ts• L120-146 src/…/axisChartOptions.ts• L157-187 src/…/LineChart.md• L61-78

Formatting and legibility

Value and category formatting

Formatting is a shared reading rule. Numeric values use consistent precision or compact notation, percentages avoid a misleading rounded zero, and dates use a grain that matches the time spacing. Applications can provide value or category formatters when the default display does not match the product language.

The same formatter reaches every place that states the value: axis labels, tooltips, data labels, scale ends, and card readings. A normalized stack is the exception in the plot: its axis and marks show the share while its tooltip keeps the original measure and adds the share.

For a number card, the value and target form one reading and the change uses its own display rule. A missing value remains empty rather than becoming zero, while a sparkline gives the reading a trend without adding an axis.

References: src/…/format.ts• L115-162 src/…/format.ts• L173-223 src/…/types.ts• L805-812 src/…/axisChartOptions.ts• L531-538 src/…/NumberCard.md• L3-11

Axis and label fit

The chart family owns label fit so each application does not need to choose an angle or width. It measures text with the chart font, keeps category labels flat when they fit, and otherwise shortens or tilts them. Crowded labels are thinned rather than allowed to cover one another. The fit uses the labels produced by the active formatter, so a custom short label gets the space it really needs.

This rule also protects the plot area. Axis space is reserved for the labels that will actually draw, while data labels and chart chrome receive their own room. Fonts settle before a plot is first measured so the first layout uses the intended text metrics.

References: src/…/axisChartCommon.ts• L383-486 src/…/axisChartCommon.ts• L495-693 src/…/useChart.ts• L60-83 src/…/format.ts• L80-113

Legend fit

The legend keeps the most meaningful entries visible when all entries cannot fit in one row. It ranks entries by their chart weight, preserves the given position for entries without a weight or for Others, and replaces the hidden tail with a +N more control.

Fit calculation accounts for the width of the count control. This avoids a boundary case where adding one entry changes the count text and makes a different number of entries fit.

References: src/…/legendOverflow.ts• L1-40 src/…/types.ts• L734-753

Color tokens

Theme-aware tokens

Chart colors are semantic tokens for the plot area. src/…/style.css defines categorical, sequential, and diverging ramps plus the axis, grid, data-label, inside-label, and cell-gap colors. src/…/tokens.ts reads the computed values from the plot’s element, so a local theme or panel can control its own chart colors.

The token reader keeps fallback values for server rendering and environments without computed styles. A shared theme observer causes chart options to rebuild when the document theme changes. This makes the plot follow the same light or dark reading as the surrounding interface.

References: src/…/style.css• L1-9 src/…/style.css• L61-79 src/…/tokens.ts• L9-25 src/…/tokens.ts• L183-227 src/…/tokens.ts• L410-427

Palette semantics

Palette names describe the relation between values, not only a set of hues. Categorical colors separate unrelated groups. Sequential colors show one direction of magnitude. Diverging colors show values around a meaningful middle such as zero.

Built-in charts choose a sensible fallback palette for their visual question. A caller can name another ramp or provide an explicit color list. Named continuous ramps are sampled across their stops, while explicit colors stay in the order supplied. Axis charts keep color identity stable when a series is hidden, and mixed marks receive sequential colors in an order that keeps thin marks readable.

References: src/…/types.ts• L32-39 src/…/tokens.ts• L244-378 src/…/axisChartCommon.ts• L122-185 src/…/scatterOptions.ts• L97-113 src/…/Overview.md• L12-15

Rendering architecture

Plot and chrome

The chart has two layers. The plot is a renderer-managed visual area. The chrome is the surrounding card, title, axis title, legend, HTML tooltip, and loading, error, and empty states. ChartContainer, ChartCard, ChartLegend, and ChartTooltip are public so an application can use the same chrome around a custom plot.

The container keeps the plot mounted while a state is shown. It hides the plot rather than rebuilding it, and each state slot replaces the full state view. Loading, error, and empty states therefore keep the card shape while allowing an application to add a retry action or a custom placeholder.

References: src/…/ChartContainer.vue• L1-131 src/…/ChartContainer.vue• L139-163 src/…/index.ts• L15-20 src/…/ChartContainer.md• L50-63 src/…/States.md• L24-35

Renderer lifecycle

ECharts-backed plots use one shared lifecycle. The plot waits for a real container size and settled fonts, creates an SVG chart instance, applies the current option, follows container resizes, and disposes the instance when the component leaves the page. The shared path avoids a separate lifecycle rule for each chart type.

The module registration boundary keeps the renderer cost tied to the marks a page uses. FunnelChart, NumberCard, and PercentageBarChart do not use ECharts: they render their own visual forms, so only ECharts-backed charts expose a live chart instance through the documented chart template-ref member. CalendarHeatmapChart uses the shared ECharts lifecycle for its calendar grid.

References: src/…/useChart.ts• L17-26 src/…/useChart.ts• L85-178 src/…/CalendarHeatmapChart.vue• L73-108 src/…/PercentageBarChart.vue• L88-116 src/…/NumberCard.vue• L157-180 src/…/types.ts• L7-10 src/…/Overview.md• L17-20 src/…/Overview.md• L172-175

Interaction model

The plot, legend, tooltip, and selection event share the normalized reading. Pointer movement opens an HTML tooltip, legend actions hide or highlight a series, and click or keyboard activation emits the selected mark with its source row. A hidden series keeps its identity and color so the remaining series do not shift. On category, time, and value axes, hit testing uses the same plotted row order as the option builder, including the nearest row on a scaled axis.

Legend state is shared by axis series and breakdown slices. The chart refuses to hide the last drawable series or slice, and it removes identities that no longer exist after the data changes. The percentage bar uses native buttons for each visible slice, while ECharts-backed plots use one keyboard stop with arrow-key movement rather than one focus stop per mark.

The same reading is exposed through a live region, so keyboard users can reach the information and activation that pointer users receive.

References: src/…/useAxisChart.ts• L75-100 src/…/useAxisChart.ts• L213-448 src/…/ChartTooltip.vue• L1-43 src/…/ChartLegend.vue• L9-37 src/…/hiddenSeries.ts• L1-31 src/…/PercentageBarChart.vue• L41-83

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the normalized model shared by the renderer option, legend, tooltip, labels, keyboard reading, and emitted selection payload. A change that updates only one consumer can show one value and emit another.
  • Preserve wide and long axis data as two input shapes of the same reading. Changes to pivot or series-cap rules also affect series identity, color assignment, hidden-series state, and seriesConfig lookup.
  • Keep carried y2 and tooltip columns at one value per category when splitBy is used. A change to that rule can silently change the meaning of every grouped row.
  • Keep breakdown grouping identical for DonutChart and PercentageBarChart. Changes to Others, duplicate category identity, or visible-share rules affect both visual forms and their controlled hidden state.
  • Keep calendar range, empty-day, duplicate-day, and date parsing rules aligned between the grid, scale, tooltip, selection event, and keyboard order.
  • Keep formatter precedence aligned between typed format props and echartOptions.axisLabel.formatter. An override must not be silently replaced by a default formatter or used for label-fit measurement under a different rule.
  • When palette tokens or ramps change, check both computed CSS values and fallback values. Theme changes and server-rendered charts must produce the same semantic roles.
  • When legend overflow changes, check the ranked order, Others placement, and the width of the +N more control together.
  • When option construction changes, preserve the separation between data meaning and renderer instructions. New shared chart behavior belongs in typed props rather than in a renderer-only override.
  • Keep reference annotations outside the data-series contract. They must not change legend entries, hidden-series state, tooltip rows, or bar spacing.
  • When chart states or chrome change, keep built-in charts and custom plots compatible with the same container, legend, tooltip, and state slots.
  • When the ECharts lifecycle changes, preserve size and font readiness, resize-driven option rebuilds, disposal, and the limits of the exposed instance. Do not apply those assumptions to FunnelChart, NumberCard, or PercentageBarChart.

Important failure modes

TriggerConsequenceGuard
A long-data change is normalized without preserving missing combinations as missingA line can fall to zero or a tooltip can point to the wrong rowKeep the shared normalized row list and use null for combinations the data does not contain
A carried column has different values in rows with one categoryThe pivot chooses one value and hides a source-data disagreementKeep the first per-category value rule and surface the development warning
A formatter is applied to the plot but not to the HTML tooltip or scaleOne measure has two visible spellingsRoute all display paths through the same formatter contract
A chart reads CSS variables directly inside an ECharts optionSVG receives unresolved var(...) values or stale colorsResolve computed chart tokens before building the option
A hidden series or slice is removed before color and identity resolutionRemaining entries change color and controlled hidden state no longer matchesKeep identities in the normalized list and filter visibility only when building the visible plot
A normalized stack uses the source measure for its axisThe plot no longer reads as a complete 100% wholePin only the axes carrying normalized stacks to 0–100 and keep the source measure in the tooltip
A reference line is hosted by a real data seriesA legend action hides the annotation or the line uses the wrong scaleBuild separate silent hosts outside the normal series list
A calendar range or date is parsed as an instant instead of a calendar dayCells shift across time zones or an empty requested range disappearsParse date-only values as day keys and resolve the explicit range before drawing
Duplicate calendar rows are treated as an aggregate without a stated ruleThe day shows a value different from the source query's intended resultKeep the last-row rule and the development warning, or pre-aggregate before charting
A legend fit calculation ignores the width of the count controlThe legend wraps or hides the wrong number of entries at the boundaryTest candidate counts with the actual +N more width
A plot is initialized before its container has size or its font has settledAxis fit is wrong and the first render can use the fallback layoutLet the shared chart lifecycle wait for size and font readiness
A custom plot replaces the chart chrome instead of composing itLoading, error, empty, tooltip, or legend behavior differs from built-in chartsCompose ChartContainer, ChartCard, ChartLegend, and ChartTooltip
External code treats the exposed ECharts instance as persistent chart stateA reactive option rebuild drops the external selection or option changeKeep durable state in props and use the instance for one-shot actions
A Sankey input contains a loop or a self-linkThe invalid flow is dropped and the graph does not show that bandGroup rows into one-way stages before sending them to the chart
A chart has no rows, no drawable values, or every series is hiddenThe chart shows its empty state rather than a data plotTreat empty input and undrawable input as empty data, and reserve the error state for a query or configuration failure

References: src/…/slices.ts• L162-209 src/…/calendarHeatmapOptions.ts• L186-213 src/…/hiddenSeries.ts• L8-30 src/…/legendOverflow.ts• L20-40 src/…/SankeyChart.md• L25-30 src/…/States.md• L8-13

Key files

FileWhy to read it
src/…/index.tsDefines the public chart package, shared chrome exports, token helpers, and public types.
src/…/types.tsDefines the shared chart meaning, data shapes, formatting hooks, events, slots, and exposed chart handle.
src/…/seriesData.tsShows how flat axis props become one normalized series model for wide and long data.
src/…/slices.tsShows how donut and percentage-bar rows become shared breakdown readings.
src/…/calendarHeatmapOptions.tsShows how dated rows become a complete calendar grid, bands, layout, and color scale.
src/…/axisChartCommon.tsDefines shared axis, scale, color, label-fit, and grid rules used across cartesian charts.
src/…/axisChartOptions.tsShows how normalized axis data becomes bar, line, area, mixed, stacked, and annotated plot options.
src/…/referenceLines.tsDefines the annotation boundary for thresholds and targets.
src/…/scatterOptions.tsShows how two value measures become grouped points with a shared size scale and reference lines.
src/…/format.tsDefines shared number, percentage, date, category, and text-width reading rules.
src/…/hiddenSeries.tsDefines stable legend visibility and last-drawable-entry protection.
src/…/legendOverflow.tsDefines ranked legend overflow and +N more fit behavior.
src/…/tokens.tsResolves theme-aware chart tokens and assigns palettes to the things a chart draws.
src/…/useChart.tsOwns the shared renderer lifecycle, SVG setup, resize behavior, and chart instance boundary.
src/…/useAxisChart.tsConnects option building to shared tooltip, legend, selection, keyboard, and state behavior.
src/…/ChartContainer.vueDefines the shared title, axis-title, plot, legend, and loading/error/empty frame.
src/…/ChartTooltip.vueDefines the HTML tooltip used by built-in and custom plots.
src/…/style.cssDefines the chart ramps and plot-area token hooks for light, dark, and local themes.