Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

sgratzl/chartjs-chart-graph

Repository files navigation

NPM PackageGithub Actions

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

force

dend_h

tree_v

radial

Works great withhttps://github.com/chartjs/chartjs-plugin-datalabels orhttps://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

seeExamples

CodePens

Graphviz Dot File Parsing

A Graphviz Dot File parsing package is located athttps://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 existingline 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 alsohttps://www.chartjs.org/docs/latest/charts/line.html. However, to avoid confusion, the line options have a defaultline prefix, e..glineBorderColor to specify the edge border color andpointBorderColor to specify the node border color.

Data Structure

data:{labels:['A','B','C'],// node labelsdatasets:[{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 labelsdatasets:[{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 onhttps://github.com/d3/d3-force/.

force

Open in CodePen

Options

Dendrogram, Tree

chart types:dendrogram,tree

The tree and dendrograms layouts are based onhttps://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 setChart.register(ForceDirectedGraphController,EdgeLine,LinearScale,PointElement);...newChart(ctx,{type:ForceDirectedGraphController.id,data:[...],});

Variant B:

import{ForceDirectedGraphChart}from'chartjs-chart-graph';newForceDirectedGraphChart(ctx,{data:[...],});

Development Environment

npm i -g yarnyarn installyarn sdks vscode

Building

yarn installyarn build

Sponsor this project

 

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp