A Choropleth chart (type: choropleth) renders maps where areas are filled based on numerical values.
Data Structure
Each data point in the datasets[].data array must contain:
.feature: The TopoJSON feature object to render..value: The numerical value used for coloring.
To process TopoJSON files, use the ChartGeo.topojson utility (exposed in the global context) to convert raw TopoJSON data into features.
Configuration Example
const us = await fetch('https://cdn.jsdelivr.net/npm/us-atlas/states-10m.json').then((r) => r.json());
// Extract features using ChartGeo.topojson
const nation = ChartGeo.topojson.feature(us, us.objects.nation).features[0];
const states = ChartGeo.topojson.feature(us, us.objects.states).features;
const alaska = states.find((d) => d.properties.name === 'Alaska');
const california = states.find((d) => d.properties.name === 'California');
const config = {
type: 'choropleth',
data: {
labels: ['Alaska', 'California'],
datasets: [{
label: 'States',
outline: nation, // Optional: outline to compute bounds
showOutline: true,
data: [
{ value: 0.4, feature: alaska },
{ value: 0.3, feature: california }
]
}]
},
options: {
scales: {
projection: {
projection: 'albersUsa' // Use D3 projection names without the 'geo' prefix
}
}
}
};
const us = await fetch('https://cdn.jsdelivr.net/npm/us-atlas/states-10m.json').then((r) => r.json());
// whole US for the outline
const nation = ChartGeo.topojson.feature(us, us.objects.nation).features[0];
// individual states
const states = ChartGeo.topojson.feature(us, us.objects.states).features;
const alaska = states.find((d) => d.properties.name === 'Alaska');
const california = states.find((d) => d.properties.name === 'California');
const config = {
data: {
labels: ['Alaska', 'California'],
datasets: [{
label: 'States',
outline: nation, // ... outline to compute bounds
showOutline: true,
data: [
{
value: 0.4,
feature: alaska // ... the feature to render
},
{
value: 0.3,
feature: california
}
]
}]
},
options: {
scales: {
projection: {
projection: 'albersUsa' // ... projection method
}
}
}
};