Sharing custom charts on the fly using Satori

Shoaib Ahmed

@pixeledcode

ReactJS Bangalore, April 6, 2024

Hi, I’m Shoaib.
Senior Frontend Engineer @CivicDataLab

Sharing custom charts on the fly using Satori

Shoaib Ahmed

@pixeledcode

ReactJS Bangalore, April 6, 2024

Hi, I’m Shoaib.
Senior Frontend Engineer @CivicDataLab

The problem

I work with dashboards on a daily basis. A common ask is having charts that need to be shareable.

screenshot of d4d platformscreenshot of constituency platform

some of the dashboards I’ve made in the past

The problem

The current implementation is pretty simple but not ideal.

Server
Client
Download Click
Screenshot the DOM
Download Image

The problem

Here’s how it works on different screen sizes.
The shared charts are not consistent.

the quick fix

ft. NextJS

Server
Client
Download Click
Initiate ECharts
Create chart using options
Convert to SVG string
Download Image

the quick fix

Thanks to route handlers, we are able to share consistent charts across different screen sizes.

let’s go plus ultra

We can improve it further by creating a custom template (React Component) before download.

Server
Client
Download Click
Generate Chart
Create React Template
Convert React to SVG
Download Image

let’s go plus ultra

ft. Satori

let’s go plus ultra

with Next.js and Satori

also, it isn’t slow..

table of performance stats of different browers while downloading charts in different ways
ChromeFirefoxSafari
Screenshot98ms128ms208ms
Route Handler45ms43ms173ms
Satori30ms23ms35ms
Satori + Route115ms112ms400ms

it solves for

custom views of shareable charts
responsive shareable charts

and as a bonus, for

browser compatibility

fin.

That’s all for today.