Skip to main content
You will end with blocks from a dashboard inside your own page, drawn as the dashboard draws them, with a click on a bar or a map region filtering the other blocks. The steps use a plain HTML page, then React, then Next.js; follow the one your app uses. Every chart reads serve’s API, so it shows the numbers of the last good build.

1. Let your app read the API

Run hatchmark serve as in Production. An app served from the same origin needs no setting. An app on another origin needs that origin listed:
The browser then sends the viewer’s cookies to serve, so your gateway decides who sees the numbers, as it does for the pages (calling from another origin). Let /_hatchmark/static/ through without a sign-in, and nothing else: browsers load the script from there without cookies from another origin. That path serves only the script, its chunks, fonts and map boundaries, which never change once built and hold none of your data. The API, the pages and the other files under /_hatchmark/ stay behind your sign-in.

2. Add charts to a plain HTML page

Load the script serve hands out and place a chart per block, named <dashboard>.<block id>:
Charts in one <hatchmark-scope> share its endpoint and theme, and a pick in one filters the others. The script comes from the same build as the API, so the two always match. Set id: on every block you embed (Dashboards): a block without one is named by its position, which changes when blocks move.

3. Use the React components

period and filters take the values the dashboard’s filters offer. To read a block’s numbers for your own UI, such as its as-of date, call useHatchmarkBlock. Install @hatchmark/react at the version of hatchmark your serve runs. To catch a misspelled block, period or filter when your app compiles, save the build’s types into your app and commit them:
This works only on a public site, since curl doesn’t sign in. Behind sign-in, copy the file from _hatchmark/api/types.d.ts in the folder you pass to hatchmark serve --out. Fetch them again when you add or rename blocks or filters.

4. Draw charts on the server with Next.js

Fetch a block in a server component and hand it to the chart, which then shows before any script runs and doesn’t fetch it again:
fetchBlock reads serve’s API from HATCHMARK_URL, such as http://hatchmark:4000/api/v1 inside your network, and passes your gateway’s headers with headers.

5. Follow picks in your app

A pick fires hatchmark-pick on the scope, or onPick on the provider, with every pick on screen:
Passing picks makes the provider controlled, so your app can show, clear or set them.

Next steps

  • Embedding: every attribute, prop, event and function.
  • Serve API: the payload each chart draws, for apps that draw their own.
  • The repository’s examples/embed folder has the three apps above, ready to run.