Dorling cartogram
Each place becomes a circle as large as its value, near its true position, none over another. Good for populations, votes and sales by country, where large places would hide small ones.
The smallest code that works. change the code, then press Run
In your framework
import { Chart } from 'nervure/react';
const spec = {
type: 'cartogram',
projection: 'naturalEarth',
geo: {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
id: 'US',
properties: { name: 'United States of America' },
geometry: { type: 'Point', coordinates: [-96, 37] },
},
{ type: 'Feature', id: 'CA', properties: { name: 'Canada' }, geometry: { type: 'Point', coordinates: [-98, 57] } },
{ type: 'Feature', id: 'MX', properties: { name: 'Mexico' }, geometry: { type: 'Point', coordinates: [-102, 24] } },
{ type: 'Feature', id: 'BR', properties: { name: 'Brazil' }, geometry: { type: 'Point', coordinates: [-54, -14] } },
{ type: 'Feature', id: 'AR', properties: { name: 'Argentina' }, geometry: { type: 'Point', coordinates: [-64, -37] } },
{ type: 'Feature', id: 'CO', properties: { name: 'Colombia' }, geometry: { type: 'Point', coordinates: [-73, 4] } },
{ type: 'Feature', id: 'PE', properties: { name: 'Peru' }, geometry: { type: 'Point', coordinates: [-75, -9] } },
{ type: 'Feature', id: 'CL', properties: { name: 'Chile' }, geometry: { type: 'Point', coordinates: [-71, -36] } },
{ type: 'Feature', id: 'GB', properties: { name: 'United Kingdom' }, geometry: { type: 'Point', coordinates: [-2, 54] } },
{ type: 'Feature', id: 'FR', properties: { name: 'France' }, geometry: { type: 'Point', coordinates: [2, 47] } },
{ type: 'Feature', id: 'DE', properties: { name: 'Germany' }, geometry: { type: 'Point', coordinates: [11, 51] } },
{ type: 'Feature', id: 'ES', properties: { name: 'Spain' }, geometry: { type: 'Point', coordinates: [-3, 40] } },
{ type: 'Feature', id: 'IT', properties: { name: 'Italy' }, geometry: { type: 'Point', coordinates: [13, 43] } },
{ type: 'Feature', id: 'PL', properties: { name: 'Poland' }, geometry: { type: 'Point', coordinates: [19, 52] } },
{ type: 'Feature', id: 'SE', properties: { name: 'Sweden' }, geometry: { type: 'Point', coordinates: [17, 62] } },
{ type: 'Feature', id: 'UA', properties: { name: 'Ukraine' }, geometry: { type: 'Point', coordinates: [31, 49] } },
{ type: 'Feature', id: 'RU', properties: { name: 'Russia' }, geometry: { type: 'Point', coordinates: [96, 60] } },
{ type: 'Feature', id: 'TR', properties: { name: 'Turkey' }, geometry: { type: 'Point', coordinates: [35, 39] } },
{ type: 'Feature', id: 'EG', properties: { name: 'Egypt' }, geometry: { type: 'Point', coordinates: [31, 27] } },
{ type: 'Feature', id: 'NG', properties: { name: 'Nigeria' }, geometry: { type: 'Point', coordinates: [9, 9] } },
{ type: 'Feature', id: 'ZA', properties: { name: 'South Africa' }, geometry: { type: 'Point', coordinates: [25, -28] } },
{ type: 'Feature', id: 'KE', properties: { name: 'Kenya' }, geometry: { type: 'Point', coordinates: [38, 0] } },
{ type: 'Feature', id: 'ET', properties: { name: 'Ethiopia' }, geometry: { type: 'Point', coordinates: [40, 9] } },
{ type: 'Feature', id: 'DZ', properties: { name: 'Algeria' }, geometry: { type: 'Point', coordinates: [2, 28] } },
{ type: 'Feature', id: 'MA', properties: { name: 'Morocco' }, geometry: { type: 'Point', coordinates: [-7, 31] } },
{ type: 'Feature', id: 'TN', properties: { name: 'Tunisia' }, geometry: { type: 'Point', coordinates: [10, 34] } },
{
type: 'Feature',
id: 'CD',
properties: { name: 'Democratic Republic of the Congo' },
geometry: { type: 'Point', coordinates: [22, -4] },
},
{ type: 'Feature', id: 'SD', properties: { name: 'Sudan' }, geometry: { type: 'Point', coordinates: [30, 15] } },
{ type: 'Feature', id: 'PS', properties: { name: 'Palestine' }, geometry: { type: 'Point', coordinates: [35, 31.5] } },
{ type: 'Feature', id: 'SA', properties: { name: 'Saudi Arabia' }, geometry: { type: 'Point', coordinates: [45, 24] } },
{ type: 'Feature', id: 'IR', properties: { name: 'Iran' }, geometry: { type: 'Point', coordinates: [54, 32] } },
{ type: 'Feature', id: 'PK', properties: { name: 'Pakistan' }, geometry: { type: 'Point', coordinates: [69, 30] } },
{ type: 'Feature', id: 'IN', properties: { name: 'India' }, geometry: { type: 'Point', coordinates: [79, 22] } },
{ type: 'Feature', id: 'BD', properties: { name: 'Bangladesh' }, geometry: { type: 'Point', coordinates: [90, 24] } },
{
type: 'Feature',
id: 'CN',
properties: { name: 'People\'s Republic of China' },
geometry: { type: 'Point', coordinates: [104, 35] },
},
{ type: 'Feature', id: 'JP', properties: { name: 'Japan' }, geometry: { type: 'Point', coordinates: [138, 36] } },
{ type: 'Feature', id: 'KR', properties: { name: 'South Korea' }, geometry: { type: 'Point', coordinates: [128, 37] } },
{ type: 'Feature', id: 'VN', properties: { name: 'Vietnam' }, geometry: { type: 'Point', coordinates: [106, 16] } },
{ type: 'Feature', id: 'TH', properties: { name: 'Thailand' }, geometry: { type: 'Point', coordinates: [101, 15] } },
{ type: 'Feature', id: 'PH', properties: { name: 'Philippines' }, geometry: { type: 'Point', coordinates: [122, 12] } },
{ type: 'Feature', id: 'ID', properties: { name: 'Indonesia' }, geometry: { type: 'Point', coordinates: [114, -1] } },
{ type: 'Feature', id: 'AU', properties: { name: 'Australia' }, geometry: { type: 'Point', coordinates: [133, -25] } },
],
},
values: {
US: 74,
CA: 57,
MX: 26,
BR: 69,
AR: 20,
CO: 20,
PE: 87,
CL: 76,
GB: 33,
FR: 36,
DE: 32,
ES: 32,
IT: 133,
PL: 7,
SE: 88,
UA: 5,
RU: 60,
TR: 35,
EG: 37,
NG: 103,
ZA: 6,
KE: 62,
ET: 83,
DZ: 64,
MA: 117,
TN: 29,
CD: 56,
SD: 76,
PS: 123,
SA: 33,
IR: 79,
PK: 51,
IN: 12,
BD: 106,
CN: 42,
JP: 64,
KR: 134,
VN: 121,
TH: 51,
PH: 22,
ID: 104,
AU: 56,
},
groups: {
US: 'Americas',
CA: 'Americas',
MX: 'Americas',
BR: 'Americas',
AR: 'Americas',
CO: 'Americas',
PE: 'Americas',
CL: 'Americas',
GB: 'Europe',
FR: 'Europe',
DE: 'Europe',
ES: 'Europe',
IT: 'Europe',
PL: 'Europe',
SE: 'Europe',
UA: 'Europe',
RU: 'Europe',
TR: 'Asia',
EG: 'Africa',
NG: 'Africa',
ZA: 'Africa',
KE: 'Africa',
ET: 'Africa',
DZ: 'Africa',
MA: 'Africa',
TN: 'Africa',
CD: 'Africa',
SD: 'Africa',
PS: 'Asia',
SA: 'Asia',
IR: 'Asia',
PK: 'Asia',
IN: 'Asia',
BD: 'Asia',
CN: 'Asia',
JP: 'Asia',
KR: 'Asia',
VN: 'Asia',
TH: 'Asia',
PH: 'Asia',
ID: 'Asia',
AU: 'Oceania',
},
};
export default function Example() {
return <Chart spec={spec} style={{ height: 340 }} />;
}Or import this chart alone: what each import weighs.
Options
Beside the fields shared by every chart (title, format, heading, export…), type cartogram takes:
/** Each place becomes a circle as large as its value, near its true position, none over another (Dorling). */
interface CartogramSpec extends Base {
type: 'cartogram';
/** GeoJSON or TopoJSON: polygons, or points at the middle of each place. */
geo: FeatureCollection | Topology;
object?: string;
projection?: MapSpec['projection'];
rotate?: [number, number];
values: Record<string, number | null>;
key?: string;
nameKey?: string;
/** Group of each place, by `key`: the circles take its colour, with a legend. */
groups?: Record<string, string>;
color?: string | string[];
legend?: boolean;
/** Draws the places, pale, under the circles: true by default. */
outline?: boolean;
onFeatureClick?: (id: string, feature: GeoFeature) => void;
}Style it
- Colours:
theme.palette,chart.setColor(name, colour), or--nervure-palettein your CSS. More - Marks:
[data-series="name"], parts:[data-part="axes"],legend,series. What you change is kept in exports. - Movement:
animation: falsedraws at once. More - Files:
chart.download('png'),svg,csv. More