Plugins 〉Leaflet Choropleth


Developer

Teofilo Sibileau

Sign up to receive occasional product news and updates:



Panel
community

Leaflet Choropleth

  • Overview
  • Installation
  • Change log
  • Related content

Grafana Leaflet Choropleth Panel

Cross-reference time-series metric data with GeoJSON to display colored polygons on a Leaflet map. A choropleth map shades regions proportionally to a statistical variable, making it easy to visualize how a measurement varies across geographic areas.

Choropleth panel screenshot

Requirements

  • Grafana >= 10.0.0
  • Node.js >= 22 (see .nvmrc)
  • pnpm (declared in package.json packageManager field)
  • Docker & Docker Compose (for the local dev environment)

Getting started

Terminal 1 — start the webpack dev build in watch mode:

pnpm install
pnpm run dev

Terminal 2 — start the Docker Compose environment:

docker compose up --build
# or: pnpm run server

Then open http://localhost:3000 in your browser. A provisioned dashboard is loaded automatically.

Note: An Ahoy configuration (.ahoy.yml) is included as an optional convenience wrapper around these commands.

Development environment

docker compose up starts two services:

  • Grafana (port 3000) — runs the plugin from the dist/ directory. Anonymous admin access is enabled so no login is required. A livereload script is injected into the Grafana HTML (see .docker/grafana/Dockerfile) so webpack rebuilds trigger automatic browser refresh.
  • InfluxDB 1.8 (port 8086) — pre-seeded with one year of hourly data via init scripts in .docker/influxdb/.

A provisioned datasource and dashboard are auto-loaded from .docker/grafana/provisioning/ on startup.

Configuration

These panel options are defined in src/module.ts:

OptionDescriptionDefault
GeoJSON DataFetch & store GeoJSON for the choropleth layer
Hot ColorColor for maximum values#ff0000
Cold ColorColor for minimum values#0000ff
GeoJSON KeyFeature property used to match metric series
Auto Fit BoundsFit map to visible features on data refreshtrue
Stroke ColorBorder color of polygons#ffffff
Stroke WidthBorder width of polygons (0–10)1
Fill OpacityOpacity of polygon fill (0–1)0.5

How it works

The plugin matches Grafana metric series to GeoJSON features using a tag-based naming convention and colors polygons with a chroma-js quantile scale on a Leaflet map with CartoDB dark tiles.

Example: given a series named metric{departamento=CONESA} and GeoJSON Key set to departamento, the plugin finds the GeoJSON feature whose departamento property equals CONESA and assigns it a color. The color is interpolated between the Cold Color (minimum value) and the Hot Color (maximum value) using a chroma-js quantile scale across all matched features.

Available scripts

CommandDescription
pnpm run devWebpack watch mode (development)
pnpm run buildProduction build
pnpm run serverStart Docker Compose environment
pnpm run testJest in watch mode (changed files only)
pnpm run test:ciJest single run (CI)
pnpm run typecheckTypeScript type-check (tsc --noEmit)
pnpm run lintESLint
pnpm run lint:fixESLint auto-fix + Prettier

Testing

Tests use Jest and React Testing Library.

pnpm run test      # watch mode — re-runs on changes
pnpm run test:ci   # single run (used in CI)

CI

GitHub Actions (.github/workflows/ci.yml) runs on every push and PR to master:

  1. build — lint, typecheck, and production build (uploads dist/ as artifact)
  2. test — runs pnpm run test:ci
  3. plugin-check — loads the built plugin into a Grafana container and verifies it is registered via the Grafana API

Project structure

src/
  module.ts              — plugin entry point & panel option definitions
  types.ts               — ChoroplethOptions interface
  components/
    ChoroplethPanel.tsx  — main React panel component + data matching
    ChoroplethMap.ts     — Leaflet map rendering + chroma-js color scale
    GeoJsonEditor.tsx    — panel editor: fetch / preview / clear GeoJSON
    GeoJsonKeyEditor.tsx — panel editor: select feature property key

Installing Leaflet Choropleth on Grafana Cloud:

For more information, visit the docs on plugin installation.

Changelog

1.0.0

Breaking Changes

  • Complete rewrite from Angular/Grunt/Bower to React/TypeScript/Webpack — Grafana >= 10.0.0 required

Features

  • GeoJSON stored in panel options (no runtime fetch) — 10761a7
  • GeoJSON Key editor scans features to populate dropdown — e6f63c1
  • Leaflet tooltips on drawn geometries — f520e9c
  • Auto Fit Bounds toggle — 34f1e0e
  • Stroke width, stroke color, fill opacity options — ac980b8
  • Support for Grafana named colors (e.g. light-blue) — d7e1313

Infrastructure / Dev Environment

  • Docker Compose dev environment: Grafana + InfluxDB with seed data — 20021ea, 733411c
  • Livereload injection for automatic browser refresh — 244f2e9
  • Grafana provisioning (datasources + dashboard) — 7d7cb8a, 612f8d5
  • Migrated from npm to pnpm — 6dd3f41
  • Migrated Travis CI to GitHub Actions (build + test + plugin-check) — 90fecfe, 7b7150f
  • Release workflow with Grafana plugin validator — 80a5955
  • Docker Compose + provisioning + seed data included in release zip
  • Screenshot in README with absolute URL for plugin catalog

Internal

  • Replaced jQuery AJAX with native fetch API
  • Replaced Angular editor template with setPanelOptions builder
  • Updated tile URL to current CARTO CDN
  • Replaced leaflet-map-zoomToGeometries with native map.fitBounds()
  • Migrated @grafana/ui Select to Combobox — f2f2d11
  • Consolidated GeoJSON key filtering logic — c6f52d7
  • Test coverage expanded — b80bf5f