Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highcharts/7-connecting-column-edges #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions highcharts-api/highcharts/7-connecting-column-edges/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const generateRandomData = (length) => Array.from({ length }, () => Math.random() * 14);

Highcharts.chart('container', {
chart: {
type: 'column',

events: {
render() {
const chart = this;
console.log(this);
jszuminski marked this conversation as resolved.
Show resolved Hide resolved

let zIndex = 3;

for(data of chart.series) {
jszuminski marked this conversation as resolved.
Show resolved Hide resolved
let prevCorner = null;
let lineIndex = 0;
zIndex++;

if(!data.lines) data.lines = [];

for(point of data.points) {
jszuminski marked this conversation as resolved.
Show resolved Hide resolved
const x = chart.plotLeft + point.shapeArgs.x,
y = chart.plotTop + point.shapeArgs.y + 1;

if(prevCorner?.length) {
jszuminski marked this conversation as resolved.
Show resolved Hide resolved
if(data.lines[lineIndex]) {
data.lines[lineIndex].attr({
d: ['M', prevCorner[0], prevCorner[1], 'L', x, y, 'z'],
'stroke-width': 1,
});

if(!data.visible) data.lines[lineIndex].attr({ 'stroke-width' : 0 });
} else {
data.lines.push(chart.renderer.path(['M', prevCorner[0], prevCorner[1], 'L', x, y, 'z']).attr({ stroke: data.color, zIndex }).add());
}
jszuminski marked this conversation as resolved.
Show resolved Hide resolved

lineIndex++;
}

prevCorner = [x + point.shapeArgs.width, y];
}
}
},
}
},

series: [{
data: generateRandomData(6)
}, {
data: generateRandomData(6)
}, {
data: generateRandomData(6)
}]
});