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

Exercise/highcharts 13 #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion highcharts-api/highcharts/13-synchronized-pies/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</head>

<body>
<div id="container"></div>
<div id="container" style="width: 600px; height: 400px; margin: 0 auto"></div>
</body>

<script src="main.js"></script>
101 changes: 101 additions & 0 deletions highcharts-api/highcharts/13-synchronized-pies/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const data = [{
name: 'Chrome',
y: 60,
}, {
name: 'Edge',
y: 15
}, {
name: 'Firefox',
y: 10
}, {
name: 'Safari',
y: 5
}, {
name: 'Internet Explorer',
y: 2.5
}, {
name: 'Other',
y: 1
}];

Highcharts.chart('container', {
chart: {
type: 'pie'
},
title: {
text: 'Chart title'
},
tooltip: {
hideDelay: 0,
followPointer: false
},
plotOptions: {
pie: {
cursor: 'pointer',
dataLabels: {
enabled: false
},
point: {
events: {
legendItemClick() {
const point = this,
series = point.series;

series.chart.series.map((seriesElement, index) => {
if (series.index !== index) {
seriesElement.points[point.index].setVisible(!point.visible);
}
});
},
mouseOver() {
const point = this,
series = point.series,
chart = point.series.chart,
secondTooltip = chart.secondTooltip || new Highcharts.Tooltip(chart, chart.tooltip.options);

series.chart.series.forEach((seriesElement, index) => {
if (series.index !== index) {
const seriesElementPoint = seriesElement.points[point.index];
seriesElementPoint.setState('hover');

if (!chart.secondTooltip) {
chart.secondTooltip = secondTooltip;
}

if (secondTooltip) {
secondTooltip.refresh(seriesElementPoint);
}
}
});
},
mouseOut() {
const secondTooltip = this.series.chart.secondTooltip;

if (secondTooltip) {
secondTooltip.hide();
}
}
}
}
},
series: {
states: {
inactive: {
opacity: 1
}
}
}
},
series: [{
name: 'Chart 1',
showInLegend: true,
data,
center: [120, 80],
size: 200
}, {
name: 'Chart 2',
data,
center: [420, 80],
size: 200
}]
});