From ECharts to TanStack Charts
A Younger Library That Reads the Stylesheet
بِسْمِ ٱللّٰهِ ٱلرَّحْمَـٰنِ ٱلرَّحِيمِ
Size
Spacing
Font
- The same chart in both libraries
- Where TanStack Charts fits this site better
- The theme comes from CSS
- Less than a seventh of the script
- A chart before any script
- Accessible by default
- One file, two renders
- A full view and a saved image
- What ECharts still does better
- Years and people
- Features only ECharts has
- Reasons that are not measured
- What the switch costs
- A chart that belongs to the page
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?
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.
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.
| ECharts | TanStack Charts | |
|---|---|---|
| SVG without a browser | yes, since 5.3 | yes |
| Light and dark switch | JavaScript draws the chart again | CSS only |
| Accessible name | none by default | required |
| Chart script after brotli | 290 KB | 39 KB |
The first TanStack chart on this site shows the last row with one more bar: ECharts imported piece by piece.
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:
- During the build, the Astro component renders the file to an SVG at the width of the article column, 672 pixels, and writes it into the HTML.
- In the browser, a small script waits until the chart is within 200 pixels of the screen. Then it loads TanStack’s DOM host and the same chart file, and hands the host the element that holds the build-time SVG. The host adopts that SVG instead of drawing a second one, lays the chart out again at the real width, and adds the tooltip and keyboard focus.
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:
- Long axis labels wrap in ECharts (
overflow: "break", which the Umami chart uses). In TanStack Charts a long category label stays on one line and takes the room it needs: in a test chart 400 pixels wide, one label took 300. - Data labels move out of each other’s way in ECharts (
labelLayout). TanStack’s docs leave that to the author: “Explicit text placement remains responsible for data-label collisions” (layout docs). - Ready-made widgets: a toolbox with save-as-image and a data view, a zoom slider, visual maps, a timeline player, scrolling legends.
- Special charts: calendar heatmaps, broken axes, pictorial bars, and 3D through echarts-gl.
- Large data: downsampling of long line series and progressive rendering. TanStack’s guide asks for aggregation before drawing and offers a Canvas renderer.
- Decal patterns for readers who cannot tell colours apart, and interface strings in 26 languages.
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:
- The name. TanStack’s libraries have a strong reputation, and that reputation invited a closer look. It decided nothing on its own (the section above shows why a famous name says little about a library this young), but it is why TanStack Charts was tested at all.
- Familiar ground. I already use TanStack Router, Query, Table, Form, DB and Hotkeys. Charts follows the same habits: typed options, a core without a framework, small entry points. A library that works like the ones around it is easier to read, to debug and to keep up to date.
- Solid.js. My other repositories use Solid.js, and TanStack Charts ships a Solid adapter. This blog is built with Astro and does not need it, but one chart library across all of them means learning one API instead of two.
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
- Two chart components. ECharts stays installed while the Umami post uses it, and its component stays maintained.
- A young dependency. Each update needs a look at the rendered charts, more than a library with years behind it would.
- Short labels. Without wrapping, category names have to fit on one line.
- Phones without JavaScript get the build-time chart scaled down, with small labels.
- Code instead of data. A chart is a TypeScript module, not a JSON file. That suits this site, but it leaves charts to people who can read TypeScript.
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.
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.
Web 7 of 8
Back to Web