From ECharts to TanStack Charts

A Younger Library That Reads the Stylesheet

25.11.2026 | 15 Jumada Al-Akhirah 1448
13 min read

بِسْمِ ٱللّٰهِ ٱلرَّحْمَـٰنِ ٱلرَّحِيمِ

The chart on this blog’s Umami post needs a bridge. ECharts cannot read CSS variables, so a script converts the site’s colours to hex, copies the reader’s font choices and draws the chart again whenever the theme or a reader setting changes. The post before this one walks through that bridge and ends with a question: is there a chart library that reads the page directly?

internal link pub/coding/web/echarts-in-astro

TanStack Charts is one. It draws with currentColor and CSS variables, so a chart follows the page’s theme the way text does. New posts on this site will inshallah draw their charts with it, and the Umami post keeps ECharts. What follows is the comparison behind that decision, the component that came out of it, and what ECharts still does better.

external link github.com/TanStack/charts

The same chart in both libraries

The test used the chart from the Umami post: two bars, script sizes in kilobytes. Each library rendered it during the build, without a browser: ECharts 6.0.0 (the version this site has installed) through its server-side SVG renderer, TanStack Charts 1.5.0 through renderChartSvg. Both SVGs were then viewed in the site’s dark and light colours, at desktop and phone width, and the script each library needs in the browser was measured in the site’s own production build.

EChartsTanStack Charts
SVG without a browseryes, since 5.3yes
Light and dark switchJavaScript draws the chart againCSS only
Accessible namenone by defaultrequired
Chart script after brotli290 KB39 KB

The first TanStack chart on this site shows the last row with one more bar: ECharts imported piece by piece.

Chart script a reader downloads for one interactive bar chart (brotli)

Esc closes · Arrow keys step through the values

Chart script a reader downloads for one interactive bar chart (brotli)

Hover over a bar, or tab to the chart and use the arrow keys. The tooltip and the marker on the focused bar come from the library, their colours from the site’s theme. The two tools under the chart open it in a full view and save it as an image.

Where TanStack Charts fits this site better

The theme comes from CSS

TanStack Charts paints text and axes with currentColor, and each series with a CSS variable from --ts-chart-1 to --ts-chart-6. The whole theme of this site’s chart component is a block of CSS that points those variables at the site’s tokens. An excerpt:

.t-chart-paint {
color: var(--tw-prose-body);
--ts-chart-1: var(--muted-foreground);
--ts-chart-2: var(--foreground);
--ts-chart-tooltip-background: var(--popover);
--ts-chart-tooltip-border: 1px solid var(--border);
}

When the reader switches between light and dark, the tokens change and the chart repaints with them, like any other element on the page. No observer, no second render, no colour conversion. The reader’s font choice arrives the same way: chart text inherits the article’s font.

ECharts can come close at build time. Its server-side SVG kept every colour as a variable when every colour was passed in as one. With a partial theme, 15 paints in the SVG fell back to ECharts’ own grey. In the browser it cannot follow at all: its colour parser reads hex, rgb, hsl and colour names, not OKLCH and not var(), so an interactive ECharts chart needs the bridge again.

Less than a seventh of the script

Measured from this site’s production build, the ECharts chart costs a reader 290 KB of script after brotli. The TanStack chart above costs 39 KB.

Part of ECharts’ size is this site’s own doing: its component imports the whole package. Importing only the bar chart, the grid, the tooltip and the SVG renderer brings it down to 135 KB in a test bundle with the same Vite version. That is less than half, and still more than three times the TanStack script. For the Umami post it would be the obvious next step; with one ECharts chart left on the site, it has not been needed so far. Both components load their script only when a chart comes close to the screen, so a page without a chart pays for neither.

A chart before any script

The ECharts chart exists only in the browser. Until its script has run, its space on the page is empty, and without JavaScript it stays empty. The TanStack chart is rendered during the build and sits in the HTML as an SVG. It appears with the rest of the page, in the right colours, and stays readable without JavaScript. The script only adds what needs a browser, as described further down.

Accessible by default

A TanStack chart is an image with a name: its SVG carries role="img" and an aria-label. This site’s component makes the name mandatory. Its alt prop is required, and a chart without one stops the build with an error. In the browser the chart takes keyboard focus, and the arrow keys step from one data point to the next. Its animations follow the reader’s reduced-motion setting by default (accessibility guide).

ECharts has no accessible name by default. Its opt-in aria option writes a generated description of the chart into an aria-label.

One file, two renders

A chart is one TypeScript file in the post’s asset folder. Shortened, the file behind the chart above:

const rows = [
{ setup: "ECharts, full", kb: 290 },
{ setup: "ECharts, tree-shaken", kb: 135 },
{ setup: "TanStack Charts", kb: 39 },
];
export default {
height: 200,
definition: (text_Px) =>
defineChart({
marks: [barX(rows, { x: "kb", y: "setup" })],
scales: {
x: { scale: scaleLinear, grid: true, axis: { tickLabels: { fontSize: text_Px } } },
y: { scale: () => scaleBand<string>(), axis: { tickLabels: { fontSize: text_Px } } },
},
tooltip: { use: tooltip, format: (point) => `${point.datum.setup}: ${point.datum.kb} KB` },
}),
} satisfies Site_Chart;

TypeScript checks the channels against the rows, so x: "kb" has to name a field the rows actually have. Because the chart is code, its data can also be computed, filtered or converted before it is drawn. And no size or colour is typed into the chart as a number: the text size arrives as text_Px from one named value in the component, and every colour is a CSS variable the rest of the site already uses. Of everything in this switch, that is the change that matters most in daily work.

The post then refers to the file by its folder and name:

<T_Chart chart="0007_Echarts_To_Tanstack/script_Size" alt="Bar chart of …" />

The component uses that one file twice:

The second render exists mainly for phones. On a phone the article column is about half as wide as the 672 pixels of the build, and an SVG scaled down to fit would shrink its labels to about half their size. The host lays the chart out at the phone’s width instead, so the labels keep their size and the bars get shorter.

The chart file cannot travel to the browser as data. ECharts options are plain data, and the ECharts component passes them along in an HTML attribute as JSON. A TanStack definition holds functions (the scale factories, the tooltip’s format), so the browser has to import the file itself. Both sides find it through one import.meta.glob over the post folders, and Vite gives each chart file its own small chunk, so a page loads only its own charts.

Reader Settings is the one place where a little script remains. TanStack takes the font from the page but the text size from the chart file, which is why every chart file receives text_Px: 12 pixels at the reader’s medium setting, multiplied by the factor the Reader Settings panel publishes as a CSS variable (smaller for S, larger for L). When the reader picks another size or font, the script builds the chart again at the new size and the host lays it out. The theme switch needs no code at all.

A full view and a saved image

Under each chart, beside its caption, sit two small tools. The first opens the chart in a full view, a sheet nearly as wide as the screen with the caption as its title. The host lays the chart out again at that width instead of enlarging the small one, so the text stays sharp and at the reader’s size, and a phone turned sideways gives the chart its whole width. The second is a download menu: a PNG, which opens everywhere, or a WebP, the smaller file with the same look, both in the colours of the current theme.

Saving had one trap. TanStack Charts can turn its SVG into an image, but an SVG decoded as an image cannot reach the page’s web fonts. Its labels fell back to a wider system font and no longer fit the layout measured for the real one: in the test, the longest category name was cut off at the left edge. Alhamdulillah, drawing the image once more with TanStack’s Canvas renderer fixed that, because canvas text uses the fonts the page has already loaded. For the flat chart above, the WebP came to 6.8 KB and the PNG to 61.6 KB.

Neither tool loads chart code before it is used. The full view reuses the code the chart already loaded, and the Canvas renderer and the export code, 8 KB after brotli, arrive with the first image a reader saves.

What ECharts still does better

Years and people

ECharts’ repository dates from 2013, and the project belongs to the Apache Software Foundation. On 25 November 2026 it had 67,799 stars on GitHub and more than 100 contributors. TanStack Charts, whose repository was created in July 2026 and reached 1.0 in October, had 879 stars and 11 contributors. Its README is open about how it was made: almost all of the implementation was produced with AI coding agents under the author’s supervision. TanStack’s earlier chart library, react-charts, never left beta and is archived.

TanStack’s reputation comes from Query, Table and Router, which have years of use behind them. Charts shares their approach (typed, a framework-free core, small entry points), and that approach is why it does well on theme, size and accessibility here. What it cannot have yet is that kind of time.

Two things lower the risk. Since 1.0 the project promises that removing an API, renaming an option or changing a documented default needs a new major version (compatibility). And it is active, Mashallah: in the 30 days to 25 November 2026 it had 56 commits and 20 merged pull requests. ECharts had no merged pull request and no commit on its main branch in that time. Its latest release, 6.1.0, is from May 2026.

Features only ECharts has

For charts in posts the gaps are small, but they are real. Checked against both libraries’ docs (ECharts options, TanStack Charts docs) and, where in doubt, by test:

Reasons that are not measured

Not every reason for the switch comes from a measurement. These are preferences, and they belong in the open as such:

None of this would carry the decision if the measurements had pointed the other way. Here they point the same way.

What the switch costs

The way back stays cheap. Each chart is one short file with its data inline, and the SVG in a built page needs nothing from the library to show.

A chart that belongs to the page

When a chart library is chosen for a site with its own theme, the feature lists are easy to compare and the bridge is easy to miss. A library that keeps its own theme makes the site rebuild, in JavaScript, what its stylesheet already says: colours, fonts, the moment to draw again, and a download to carry it all. A library that draws with CSS leaves the stylesheet as the one place where the look is decided, and the chart becomes one more element that follows it.

FAQ
Can TanStack Charts render a chart without JavaScript?

Yes. Its renderChartSvg function turns a chart definition into an SVG string without a browser, so the chart can be written into the HTML at build time. This site does that and uses JavaScript only for what needs a browser: the layout at the real width, the tooltip and keyboard focus. Without JavaScript the reader sees the build-time chart, scaled to fit the screen.

Does TanStack Charts need an adapter for Astro?

No. It ships adapters for several frameworks (React, Vue, Svelte, Solid, Angular and more), none for Astro, and none is needed. The core renders the SVG during the build, and the framework-free DOM host from @tanstack/charts/dom mounts on a plain element in the browser.

Should existing ECharts charts be moved to TanStack Charts?

Only with a reason. The one ECharts chart on this site stays: it works, and it wraps long category labels, which TanStack Charts does not do. Moving a chart costs one TypeScript file and possibly shorter labels. What it gains is a smaller script and a theme that needs no bridge.