Organization chart
author(s): Torstein Hønsi
by Black Label
HTML
<script src="https://code.highcharts.com/highcharts.src.js"></script>
<script src="https://code.highcharts.com/modules/sankey.src.js"></script>
<script src="https://code.highcharts.com/modules/organization.src.js"></script>
<figure class="highcharts-figure">
<div id="container"></div>
<p class="highcharts-description">
Organization charts are a common case of hierarchical network charts,
where the parent/child relationships between nodes are visualized.
Highcharts includes a dedicated organization chart type that streamlines
the process of creating these types of visualizations.
</p>
</figure>
CSS
.highcharts-series-0 {
display: grid;
}
.highcharts-series-0 .highcharts-node {
}
JavaScript
(function(H) {
const SankeySeries = H.seriesTypes.sankey;
const { merge } = H;
H.seriesTypes.organization.prototype.translateNode = function(node, column) {
SankeySeries.prototype.translateNode.call(this, node, column);
const translationFactor = this.translationFactor,
sum = node.getSum(),
nodeHeight = Math.max(
Math.round(sum * translationFactor),
this.options.minLinkWidth
),
nodeWidth = Math.round(this.nodeWidth);
let parentNode = node.hangsFrom,
indent = this.options.hangingIndent || 0,
sign = this.chart.inverted ? -1 : 1,
shapeArgs = node.shapeArgs,
indentLogic = this.options.hangingIndentTranslation,
minLength = this.options.minNodeLength || 10;
if (parentNode) {
if (indentLogic === 'cumulative') {
// Move to the right:
shapeArgs.height -= indent;
shapeArgs.y -= sign * indent;
while (parentNode) {
shapeArgs.y += sign * indent;
parentNode = parentNode.hangsFrom;
}
} else if (indentLogic === 'shrink') {
// Resize the node:
while (parentNode &&
shapeArgs.height > indent + minLength) {
shapeArgs.height -= indent;
parentNode = parentNode.hangsFrom;
}
} else {
// indentLogic === "inherit"
// Do nothing (v9.3.2 and prev versions):
shapeArgs.height -= indent;
if (!this.chart.inverted) {
shapeArgs.y += indent;
}
}
}
node.nodeHeight = this.chart.inverted ?
shapeArgs.width :
shapeArgs.height;
node.shapeArgs = merge(node.shapeArgs, {
x: node.shapeArgs.x + (nodeWidth / 2) - (node.shapeArgs.width / 2),
y: node.shapeArgs.y + (nodeHeight / 2) - (node.shapeArgs.height / 2)
});
}
}(Highcharts))
Highcharts.chart('container', {
chart: {
height: 600,
...