• Stars
    star
    156
  • Rank 232,165 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Chart.js Graph-like Charts (tree, force directed)

Chart.js Graphs

NPM Package Github Actions

Chart.js module for charting graphs. Adding new chart types: graph, forceDirectedGraph, dendrogram, and tree.

force

dend_h

tree_v

radial

Works great with https://github.com/chartjs/chartjs-plugin-datalabels or https://github.com/chrispahm/chartjs-plugin-dragdata

data label

Open in CodePen

Related Plugins

Check out also my other chart.js plugins:

Install

npm install --save chart.js chartjs-chart-graph

Usage

see Samples on Github

CodePens

Graphviz Dot File Parsing

A Graphviz Dot File parsing package is located at https://github.com/sgratzl/chartjs-chart-graph-dot-parser. It creates compatible data structures to be consumed by this plugin.

Styling

The new chart types are based on the existing line controller. Tho, instead of showing a line per dataset it shows edges as lines. Therefore, the styling options for points and lines are the same. See also https://www.chartjs.org/docs/latest/charts/line.html. However, to avoid confusion, the line options have a default line prefix, e..g lineBorderColor to specify the edge border color and pointBorderColor to specify the node border color.

Data Structure

data: {
  labels: ['A', 'B', 'C'], // node labels
  datasets: [{
    data: [ // nodes as objects
      { x: 1, y: 2 }, // x, y will be set by the force directed graph and can be omitted
      { x: 3, y: 1 },
      { x: 5, y: 3 }
    ],
    edges: [ // edge list where source/target refers to the node index
      { source: 0, target: 1},
      { source: 0, target: 2}
    ]
  }]
},

Alternative structure for trees

data: {
  labels: ['A', 'B', 'C'], // node labels
  datasets: [{
    data: [ // nodes as objects
      { x: 1, y: 2 }, // x, y will be set by the force directed graph and can be omitted
      { x: 3, y: 1, parent: 0 },
      { x: 5, y: 3, parent: 0 }
    ]
  }]
},

Force Directed Graph

chart type: forceDirectedGraph

Computes the x,y position of nodes based on a force simulation. It is based on https://github.com/d3/d3-force/.

force

Open in CodePen

Options

Dendrogram, Tree

chart types: dendrogram, tree

The tree and dendrograms layouts are based on https://github.com/d3/d3-hierarchy.

Dendrogram Horizontal

dend_h

Open in CodePen

Dendrogram Vertical

dend_v

Open in CodePen

Dendrogram Radial

radial

Open in CodePen

Tidy Tree Horizontal

tree_h

Open in CodePen

Tidy Tree Vertical

tree_v

Open in CodePen

Tidy Tree Radial

radial

Open in CodePen

Options

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, LinearScale, PointElement } from 'chart.js';
import { ForceDirectedGraphController, EdgeLine } from 'chartjs-chart-graph';

// register controller in chart.js and ensure the defaults are set
Chart.register(ForceDirectedGraphController, EdgeLine, LinearScale, PointElement);
...

new Chart(ctx, {
  type: ForceDirectedGraphController.id,
  data: [...],
});

Variant B:

import { ForceDirectedGraphChart } from 'chartjs-chart-graph';

new ForceDirectedGraphChart(ctx, {
  data: [...],
});

Development Environment

npm i -g yarn
yarn install
yarn sdks vscode

Building

yarn install
yarn build

More Repositories

1

slack-cleaner

delete slack messages and files. An improved version is at:
Python
365
star
2

chartjs-chart-geo

Chart.js Choropleth and Bubble Maps
TypeScript
319
star
3

d3tutorial

📊📈 A D3 v7 tutorial - interactive bar chart and multiple coordinated views (MCV)
HTML
246
star
4

slack_cleaner2

📝 Python3 module for deleting Slack messages and files using the Slack REST API
Python
224
star
5

chartjs-chart-boxplot

Chart.js Box Plots and Violin Plot Charts
TypeScript
94
star
6

chartjs-chart-wordcloud

Chart.js Word Clouds
TypeScript
91
star
7

cytoscape.js-layers

Cytoscape.js plugin for simplified layers (svg, canvas, html)
TypeScript
52
star
8

chartjs-plugin-hierarchical

Chart.js scale for hierarchical tree-like data structure
TypeScript
47
star
9

chartjs-chart-error-bars

Chart.js Plugin for showing error bars for various chart types
TypeScript
39
star
10

chartjs-chart-pcp

Chart.js Parallel Coordinates Plot
TypeScript
20
star
11

lineup-lite

LineUp-lite is an extension of the excellent react-table library for rendering beautiful interactive table visualizations based on the LineUp ranking visualization technique.
TypeScript
15
star
12

cytoscape.js-overlays

Cytoscape.js plugin for rendering node overlays
TypeScript
15
star
13

chartjs-chart-funnel

Chart.js Funnel chart
TypeScript
9
star
14

developer_webhook_bot

Telegram Bot Experiment for forwarding Webhooks
TypeScript
5
star
15

d3boilerplate

JavaScript
3
star
16

chartjs-chart-graph-dot-parser

Graphviz DOT parser for chartjs-chart-graph
JavaScript
3
star
17

yet_another_rss_bot

Yet Another RSS Bot for Telegram
TypeScript
3
star
18

chartjs-chart-graph-dagre

Chart.js Graph extension using the Dagre layouting library
TypeScript
3
star
19

covid19_demos

Demos repository how @lineupjs and @upsetjs can be used to explore Covid 19 data
Jupyter Notebook
2
star
20

boxplots

A simple boxplot Javascript library with various quantiles options (like R)
TypeScript
2
star
21

vue-chartjs-boxplot

Vue.js Boxplot Chart.js example
Vue
2
star
22

lineup_if_fi

Exploring Items and Features with IF, FI-Tables
JavaScript
2
star
23

ts-library-template

Template Repo based on rollup for yarn 2
JavaScript
2
star
24

ipython-tutorial-VA2015

IPython tutorial given as part of Visual Analytics winter term 2015/2016 at Johannes Kepler University
2
star
25

lineup_remote

LineUp remote data test
JavaScript
1
star
26

yacobo

Yet another COVID-19 Board
TypeScript
1
star
27

oogl

C++
1
star
28

covidcast-env

Jupyter Notebook
1
star
29

dash-tree-checklist

Tree Checklist component for Plotly Dash
TypeScript
1
star
30

chartjs-esm-facade

OUTDATED with beta version of chart.js 3
JavaScript
1
star
31

lineup_propsperity

JavaScript
1
star
32

vega-lite-examples

Advanced Vega Lite Examples
HTML
1
star