Create a density map
This is the official documentation of the @forestadmin/agent
Node.js agent.

This last example shows how you can achieve virtually anything since you are coding in a sandbox. There's no limit to what you can do with Smart Charts.
In this snippet, notice how we import the D3js ↗ library. Of course, you can choose to use any other library of your choice.
The resulting chart can be resized to fit your use.
agent.addChart('densitymap', async (context, resultBuilder) => {
// Load contours to draw the map
// Ref.: https://github.com/d3/d3-fetch/blob/v2.0.0/README.md#json
const contours = await superagent
.get(
`https://static.observableusercontent.com/files/6b1776f5a0a0e76e6428805c0` +
`074a8f262e3f34b1b50944da27903e014b409958dc29b03a1c9cc331949d6a2a404c19` +
`dfd0d9d36d9c32274e6ffbc07c11350ee?response-content-disposition=attachm` +
`ent%3Bfilename*%3DUTF-8%27%27counties-albers-10m.json`,
)
.buffer(true);
// Load population data
const population = await superagent
.get(
`https://static.observableusercontent.com/files/beb56a2d9534662123fa352ff` +
`ff2db8472e481776fcc1608ee4adbd532ea9ccf2f1decc004d57adc76735478ee68c0f` +
`d18931ba01fc859ee4901deb1bee2ed1b?response-content-disposition=attachm` +
`ent%3Bfilename*%3DUTF-8%27%27population.json`,
)
.buffer(true);
return resultBuilder.smart({
contours: JSON.parse(contours.body.toString('utf-8')),
population: JSON.parse(population.body.toString('utf-8')),
});
});
Last updated
Was this helpful?