The Map chart renders geographic data as a choropleth or region-highlight map. In practice this usually means one simple thing: you have data tied to places and you want to show it on a map.
Common examples include visited countries, regional performance, market presence, or anything else where geography matters more than a precise number.
Map charts combine two ingredients:
- Geographic shapes — the borders of regions (
GeoJSONorTopoJSON). - Value data — an array of items that match those regions by ID.
The map provides the geometry; your data decides what gets highlighted.
Geographic data
Pass a URL to fetch, or an inline object — whichever fits your pipeline.
// TopoJSON from a local file
new RareCharts.Map('#chart', {
topoUrl: '/assets/charts/data/countries-110m.json',
topoObject: 'countries', // named object inside the topology
});
// GeoJSON fetched from a URL
new RareCharts.Map('#chart', {
geoUrl: '/data/europe.geojson',
});
// Inline GeoJSON FeatureCollection
new RareCharts.Map('#chart', {
geoData: myFeatureCollection,
});
RareCharts supports both GeoJSON and TopoJSON.
In practice TopoJSON is usually the better choice for world maps: it is smaller, simpler to ship with your bundle, and avoids duplicated borders between neighboring regions.
Open geographic datasets
A convenient public source of world map data is the world-atlas dataset: https://cdn.jsdelivr.net/npm/world-atlas@2/.
It provides several ready-to-use TopoJSON files that differ only by geometric detail:
| File | Description |
|---|---|
countries-110m.json |
Smallest dataset. Best for dashboards and simple maps (~100 Kb) |
countries-50m.json |
Medium detail. Good default for most projects (~750 Kb) |
countries-10m.json |
High detail. Suitable for zoomable or full-screen maps (~3.5 Mb) |
Example:
new RareCharts.Map('#chart', {
topoUrl: 'https://cdn.jsdelivr.net/npm/world-atlas@2/countries-50m.json',
topoObject: 'countries'
});
These files use ISO 3166-1 numeric country codes as feature.id, which makes them easy to match with data items.
Value data
Each item in the data array identifies a geographic feature and optionally carries a value and color:
chart.setData([
{ id: '250', label: 'France', color: '#00aaff' },
{ id: '276', label: 'Germany', color: '#00aaff' },
{ id: '380', label: 'Italy', value: 42 },
]);
The id field must match either feature.id or a property inside feature.properties.
For example:
- world-atlas TopoJSON uses numeric ISO 3166-1 country codes as
feature.id - other datasets often store identifiers inside
feature.properties
If needed, use the idField option to tell the chart which property should be used.
Projections
RareCharts supports five projections:
| Name | Description |
|---|---|
'naturalEarth1' |
Default. Balanced projection suitable for most maps |
'mercator' |
Familiar web-map projection. Often used for regional maps |
'equalEarth' |
Equal-area projection. Useful when region size matters |
'orthographic' |
Globe view. Mostly for visual context |
'identity' |
No geographic projection. Useful when your GeoJSON is already in screen coordinates or a custom planar space |
The chart automatically fits the projection to the loaded features using fitExtent, so you normally do not need to set scale or center manually.
Coloring
Regions are colored in three ways, in order of priority:
- Per-item
color— explicit CSS color on a data item. matchFill— applied to matched regions without their own color.defaultFill— applied to regions that have no matching data.
For a simple highlight map (visited countries, market presence), a single matchFill is usually enough.
For a choropleth map, you will typically compute colors yourself using a scale and pass them through the color field.
Default colors used by the chart come from the RareCharts theme. They are defined in: /src/core/theme.js. The map section of the theme defines values such as matchFill, unmatchedFill, border, and hover behavior. In most cases it is better to adjust those defaults in the theme rather than overriding colors in every chart instance.
Tooltip
The default tooltip shows the region name and, if present, the value for every region on the map, including regions with no matching data item.
If you need something more specific, override it:
tooltipFormat: ({ feature, item }) => `
<strong>${item?.label ?? feature.properties.name}</strong>
<div>Revenue: $${item?.value?.toLocaleString()}</div>
`
The formatter receives both the raw feature and the matched item, so you can display whatever makes sense. For unmatched regions, item will be null.
Map chart options
Common options shared by all chart types (title, subtitle, source, theme) are documented on the Settings page.
| Option | Type | Default | Description |
|---|---|---|---|
Layout |
|||
height |
number | 400 |
Container height in px. Width is always 100% of the container. |
fitPadding |
number | 20 |
Padding in px around the feature bounds when fitting the projection. |
Geographic data |
|||
geoUrl |
string | — | URL of a GeoJSON FeatureCollection to fetch via d3.json(). |
geoData |
object | — | Inline GeoJSON FeatureCollection or single Feature. |
topoUrl |
string | — | URL of a TopoJSON topology to fetch. |
topoData |
object | — | Inline TopoJSON topology object. |
topoObject |
string | first object |
Named object inside the topology to extract. Defaults to the first key in topology.objects.
|
featureFilter |
function | — | Optional filter applied to extracted features before rendering. Receives feature and should return true to keep it. |
clipExtent |
[[lon, lat], [lon, lat]] |
— | Geographic bounding box used to keep only polygons intersecting that extent. |
idField |
string | 'id' |
Feature property used as ID when feature.id is absent.Falls back through iso_a2, iso_a3, ISO_A2, ISO_A3 automatically.
|
Projection |
|||
projection |
'naturalEarth1' | 'mercator' | 'equalEarth' | 'orthographic' | 'identity' |
'naturalEarth1' |
D3 geo projection to use for rendering. |
rotate |
array | — | Optional projection rotation passed to projection.rotate([lambda, phi, gamma]) when supported by the chosen projection. |
Colors |
|||
defaultFill |
CSS color | theme.surface |
Fill for regions with no matching data item. |
matchFill |
CSS color | theme.accent |
Fill for matched regions that have no explicit color field. |
hoverFill |
CSS color | auto | Fill on mouse-over. Defaults to a lighter version of matchFill. |
oceanColor |
CSS color | 'transparent' |
SVG background fill (the "ocean" behind land features). |
borderColor |
CSS color | theme.border |
Stroke color for feature borders. |
borderWidth |
number | 0.5 |
Border stroke-width in px. |
Interaction |
|||
zoom |
boolean | false |
Enable scroll-to-zoom and drag-to-pan. |
zoomExtent |
array | [0.8, 12] |
Minimum and maximum zoom scale used when zoom is enabled. |
tooltipFormat |
function | built-in | ({ feature, item }) => html — custom tooltip for any region. item is null when no data item matches. |
Data fields
| Field | Type | Description |
|---|---|---|
id |
string | number | Required. Must match feature.id or the resolved idField property. |
label |
string | Display name used in the tooltip. Falls back to feature.properties.name. |
value |
number | Optional numeric value. Shown in the default tooltip; available in tooltipFormat. |
color |
CSS color | Explicit fill for this region. Overrides matchFill. |
Minimal example
new RareCharts.Map('#chart', {
title: 'Market Presence',
topoUrl: '/assets/charts/data/countries-110m.json',
topoObject: 'countries',
height: 400,
matchFill: '#00aaff',
zoom: true,
}).setData([
{ id: '840', label: 'United States' },
{ id: '276', label: 'Germany' },
{ id: '392', label: 'Japan' },
]);
In practice the workflow is usually straightforward:
- Load a geographic file, usually TopoJSON.
- Match your data to regions by ID.
- Decide which regions should be highlighted.
- Leave the projection and fitting to the chart unless you have a specific reason not to.
For most use cases, that is enough. The difficult part is rarely drawing the map itself. It is usually getting the region IDs to line up, finding a geography file that does not look terrible, and resisting the temptation to turn a simple highlight map into a geopolitical event.