Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion highcharts-api/highcharts/14-synchronized-pies/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

</head>

<body>
<div id="container"></div>
</body>

<script src="main.js"></script>
<script src="main.js"></script>
132 changes: 132 additions & 0 deletions highcharts-api/highcharts/14-synchronized-pies/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
const data = [
{ name: 'Commerce', y: 52 },
{ name: 'Engineering', y: 20 },
{ name: 'Financial Services', y: 15 },
{ name: 'Logistics, Aviation & Shipping', y: 5 },
{ name: 'Seafood & Marine', y: 7 },
{ name: 'Corporate Services & others', y: 1 }
];

Highcharts.Pointer.prototype.reset = function() {
return undefined;
};

Highcharts.chart('container', {
chart: {
type: 'pie',
events: {
load: function() {
const chart = this;
const { series } = chart;
const legendItems = chart.legend.allItems;

chart.customTooltips = [ chart.tooltip ];
series.slice(1).forEach(s => {
const tooltip = new Highcharts.Tooltip(chart, {
...chart.options.tooltip,
animation: false
});
tooltip.pointer = chart.tooltip.pointer;
chart.customTooltips.push(tooltip);
});

legendItems?.forEach(legendItem => {
const legendGroup = legendItem.legendItem?.group;
if (!legendGroup?.element) return;
const legendItemElement = legendGroup.element;

legendItemElement.addEventListener('mouseover', (e) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to pass the event here? it's not used anywhere

@dqmrf dqmrf Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not used, then it's not needed. My bad

if (!legendItem.visible) return;

const activePoints = series.flatMap(s => {
const point = s.points[legendItem.index];
point.onMouseOver();
return point;
});

activePoints.forEach((p, i) =>
chart.customTooltips[i].refresh(p));
});

legendItemElement.addEventListener('mouseout', () => {
series.forEach(s => {
s.points.forEach(point => {
if (legendItem.index !== point.index) {
point.onMouseOut();
point.setState('normal');
}
});
});

chart.customTooltips.forEach(t => t.hide(0));
});
});
}
}
},
tooltip: {
animation: false
},
plotOptions: {
pie: {
dataLabels: {
enabled: false
},
showInLegend: true,
point: {
events: {
mouseOver: function() {
const point = this;
const { chart } = this.series;
const activePoints = [point];

chart.series.forEach(s => {
if (point.series.index !== s.index) {
s.points[point.index].setState('hover');
activePoints.push(s.points[point.index]);
}
});

activePoints.forEach((p, i) =>
chart.customTooltips[i].refresh(p));
},
mouseOut: function() {
const point = this;
const { chart } = this.series;

chart.customTooltips.forEach(t => t.hide(0));
}
}
}
}
},
series: [
{
data,
center: ['25%', '50%'],
point: {
events: {
legendItemClick: function() {
const { point } = this;
const { chart } = this.series;

chart.series.forEach(s => {
if (point.series.index === s.index) return;
const nextPoint = s.points[point.index];
nextPoint.setVisible(point.visible, false);
if (!point.visible) nextPoint.setState('inactive');
});

chart.customTooltips.forEach(t => t.hide(0));
chart.redraw();
}
}
}
},
{
data,
center: ['75%', '50%'],
showInLegend: false
},
]
});