All Projects → sgratzl → Chartjs Chart Geo

sgratzl / Chartjs Chart Geo

Licence: mit
Chart.js Choropleth and Bubble Maps

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Chartjs Chart Geo

Map
PHP Map package for easy and elegant handling of PHP arrays as array-like map objects
Stars: ✭ 1,180 (+1155.32%)
Mutual labels:  map
Quizzity
A fast-paced geography quiz
Stars: ✭ 80 (-14.89%)
Mutual labels:  map
Instaloctrack
An Instagram OSINT tool to collect all the geotagged locations available on an Instagram profile in order to plot them on a map, and dump them in a JSON.
Stars: ✭ 85 (-9.57%)
Mutual labels:  map
Hms Mapkit Demo
HMS Map Kit demo provides an example of intergrating HMS Map Android SDK. Personalizing how your map displays and interacts with your users tailors their experience to them
Stars: ✭ 76 (-19.15%)
Mutual labels:  map
Yiqingditu
新冠肺炎,疫情地图
Stars: ✭ 79 (-15.96%)
Mutual labels:  map
Dyno
Package dyno is a utility to work with dynamic objects at ease.
Stars: ✭ 81 (-13.83%)
Mutual labels:  map
Exploretrees Sg
🌳 Explore Trees in Singapore 🇸🇬
Stars: ✭ 68 (-27.66%)
Mutual labels:  map
Chartjs Chart Box And Violin Plot
Chart.js Box Plot addon
Stars: ✭ 91 (-3.19%)
Mutual labels:  chartjs
Bob74 ipl
Topic on FiveM Forums:
Stars: ✭ 80 (-14.89%)
Mutual labels:  map
Chartjs Plugin Stacked100
This plugin for Chart.js that makes your bar chart to 100% stacked bar chart.
Stars: ✭ 84 (-10.64%)
Mutual labels:  chartjs
Agm Direction
This is the directive for @agm/core (not official)
Stars: ✭ 77 (-18.09%)
Mutual labels:  map
Itiriri Async
A library for asynchronous iteration.
Stars: ✭ 78 (-17.02%)
Mutual labels:  map
Pulsator
Pulse animation for iOS
Stars: ✭ 1,238 (+1217.02%)
Mutual labels:  map
Agilework
可视化低代码快速开发平台,面向业务、企业管理系统定制开发平台和应用平台,包括设计器、应用端。提供业务配置和集成开发能力,用户通过可视化拖拉拽配置式操作即可快速构建出能同时在PC和移动端运行的各类管理系统,对于企业客户的信息系统在管理模式、业务流程、表单界面、数据可视化展示、IoT管控等个性化需求,可以通过设计器,快速的进行个性化配置。并支持企业微信,公众号,钉钉等移动集成,实现用户跨区域移动办公。从而构建企业个性化的行业应用、集成应用和复杂的业务报表。
Stars: ✭ 76 (-19.15%)
Mutual labels:  map
Imtools
Fast and memory-efficient immutable collections and helper data structures
Stars: ✭ 85 (-9.57%)
Mutual labels:  map
Unity Plane Mesh Splitter
Unity Plane Mesh Splitter
Stars: ✭ 71 (-24.47%)
Mutual labels:  map
Bmi Calculator
React Hooks app for calculating BMI
Stars: ✭ 80 (-14.89%)
Mutual labels:  chartjs
Eternal
A C++14 compile-time/constexpr map and hash map with minimal binary footprint
Stars: ✭ 93 (-1.06%)
Mutual labels:  map
Routegen
Define your API and SPA routes in one place. Use them anywhere. Only 1.3kb.
Stars: ✭ 86 (-8.51%)
Mutual labels:  map
Chinamapview
自定义View,可缩放、可平移、可点击的中国地图,有中国地图的全部省份,具备每个省份的点击接口
Stars: ✭ 1,250 (+1229.79%)
Mutual labels:  map

Chart.js Geo

NPM Package Github Actions

Chart.js module for charting maps with legends. Adding new chart types: choropleth and bubbleMap.

Works only with Chart.js >= 3.0.0-alpha.2

Choropleth

Open in CodePen

Earth Choropleth

Open in CodePen

Bubble Map

Open in CodePen

works great with https://github.com/chartjs/chartjs-plugin-datalabels

Install

npm install --save [email protected] [email protected]

Usage

see Samples on Github

CodePens

Options

The option can be set globally or per dataset

see https://github.com/sgratzl/chartjs-chart-geo/blob/develop/src/controllers/geo.ts#L213

Choropleth

A Choropleth (chart type: choropleth) is used to render maps with the area filled according to some numerical value.

Choropleth

Open in CodePen

Earth Choropleth

Open in CodePen

Data Structure

A data point has to have a .feature property containing the feature to render and a .value property containing the value for the coloring.

TopoJson is packaged with this plugin to convert data, it is exposed as ChartGeo.topojson in the global context. However, this plugin doesn't include any topojson files itself. Some useful resources I found so far:

const us = await fetch('https://unpkg.com/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: {
      xy: {
        projection: 'albersUsa' // ... projection method
      }
    }
  }
};

Styling

The styling of the new element GeoFeature is based on Rectangle Element with some additional options for the outline and graticule.

see https://github.com/sgratzl/chartjs-chart-geo/blob/develop/src/elements/geoFeature.ts#L5

Legend and Color Scale

The coloring of the nodes will be done with a special color scale. The scale itself is based on a linear scale.

see

Bubble Map

A Bubble Map (chart type: bubbleMap) aka Proportional Symbol is used to render maps with dots that are scaled according to some numerical value. It is based on a regular bubble chart where the positioning is done using latitude and longtitude with an additional radiusScale to create a legend for the different radi.

Bubble Map

Open in CodePen

Data Structure

see Bubble Chart. Alternatively to x and y, the following structure can be used:

interface IBubbleMapPoint {
  longitude: number;
  latitude: number;
  value: number;
}

Note: instead of using the r attribute as in a regular bubble chart, the value attribute is used, which is picked up by the radiusScale to convert it to an actual pixel radius value.

Styling

A regular point is used and thus supports the Point Element styling options. In addition, the outline* and graticule* are supported.

Legend

Similar to the choropleth chart a new radiusScale is used to map the values to symbol radius size. The scale itself is based on a linear scale.

see

Scales

A new scale projection is registered and used by default by Choropleth and BubbleMap. It provides just one option to specify the projection method. The available methods are the one from https://github.com/d3/d3-geo#projections. Just remove the geo prefix. Alternatively, the projection method instance can be directly given.

see https://github.com/sgratzl/chartjs-chart-geo/blob/develop/src/scales/projection.ts#L49

ESM and Tree Shaking

The ESM build of the library supports tree shaking thus having no side effects. As a consequence the chart.js library won't be automatically manipulated nor new controllers automatically registered. One has to manually import and register them.

Variant A:

import { Chart } from 'chart.js';
import { ChoroplethController } from 'chartjs-chart-geo';

// register controller in chart.js and ensure the defaults are set
ChoroplethController.register();

const chart = new Chart(document.getElementById('canvas').getContext('2d'), {
  type: ChoroplethController.id,
  data: {
    // ...
  },
});

Variant B:

import { ChoroplethChart } from 'chartjs-chart-geo';

const chart = new ChoroplethChart(document.getElementById('canvas').getContext('2d'), {
  data: {
    //...
  },
});

Development Environment

npm i -g yarn
yarn set version 2
cat .yarnrc_patch.yml >> .yarnrc.yml
yarn
yarn pnpify --sdk

Common commands

yarn compile
yarn test
yarn lint
yarn fix
yarn build
yarn docs
yarn release
yarn release:pre
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].