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/13 syncronized pies #13

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 5 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
79 changes: 79 additions & 0 deletions highcharts-api/highcharts/13-synchronized-pies/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const commonData = [{
name: 'space-ninjas',
y: 60
},
{
name: 'bananas',
y: 25
},
{
name: 'trollfaces',
y: 15
},
];

const c = Highcharts.chart('container', {
chart: {
type: 'pie',
title: {
text: ''
}
},
plotOptions: {
pie: {
events: {
mouseOver: function() {
console.log('AWDAWD');
}
}
}
},

series: [{
center: ['25%'],
data: commonData,
showInLegend: true,
point: {
events: {
legendItemClick: function(e) {
this.series.chart.series[1].data.forEach(d => {
if (d.name === this.name) {
d.update({
visible: (d.visible === false ? true : false)
})
}
});
},
mouseOver: function(e) {
Copy link

@hihajdus hihajdus Sep 30, 2022

Choose a reason for hiding this comment

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

To do:

  • Add a feature to show the tooltip in both series.
    (So that when the cursor hovers over a point in series1, the tooltip also appears in series2, and vice versa)

Tip:
You can get to the tooltip options from point.events.mouseOver and point.events.mouseOut this.series.chart.tooltip

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I will try this now!

this.series.chart.series[1].data.forEach(d => {
d.name === this.name ? d.setState('hover') : d.setState('inactive');
});
},
}
}
},
{
center: ['75%'],
data: commonData
}
]
});

c.legend.allItems.forEach(l => { //trying to make legend behave uniformily

l.legendItem.element.addEventListener('mouseover', () => {
c.series.forEach(ser => {
ser.points.forEach(d => {
d.name === l.name ? d.setState('hover') : d.setState('inactive');
})
});
})

l.legendItem.element.addEventListener('mouseout', () => {
c.series.forEach(ser => {
ser.points.forEach(d => {
d.setState('normal');
})
});
});
});