Highcharts treemap link legends
I would like to link a pair of areas to a legend in highcharts treemap so that clicking on the legend turns both the area on/off.
For example, in this fiddle, if I click 'America' in the legend I would like it to turn off both the areas covering 'America' & similarly to do with 'Australia'.
Fiddle here.
$(function() {
var H = Highcharts;
H.addEvent(H.Legend, 'afterGetAllItems', function(e) {
e.allItems.splice(1, 2);
});
$('#container').highcharts({
chart: {
type: 'treemap'
},
plotOptions: {
series: {
events: {
legendItemClick: function (event) {
alert('Done');
}
}
}
},
series: [{
data: [{
'name': 'Americas',
'value': 52976,
'color': 'rgba(47,126,216,1)'
}, {
'name': 'Australia',
'value': 41219,
'color': 'rgba(13,35,58,1)'
}, {
'name': 'Americas',
'value': 52976,
'color': 'rgba(47,126,216,1)'
}, {
'name': 'Australia',
'value': 41219,
'color': 'rgba(13,35,58,1)'
}],
legendType: 'point',
showInLegend: true
}]
});
});
highcharts
add a comment |
I would like to link a pair of areas to a legend in highcharts treemap so that clicking on the legend turns both the area on/off.
For example, in this fiddle, if I click 'America' in the legend I would like it to turn off both the areas covering 'America' & similarly to do with 'Australia'.
Fiddle here.
$(function() {
var H = Highcharts;
H.addEvent(H.Legend, 'afterGetAllItems', function(e) {
e.allItems.splice(1, 2);
});
$('#container').highcharts({
chart: {
type: 'treemap'
},
plotOptions: {
series: {
events: {
legendItemClick: function (event) {
alert('Done');
}
}
}
},
series: [{
data: [{
'name': 'Americas',
'value': 52976,
'color': 'rgba(47,126,216,1)'
}, {
'name': 'Australia',
'value': 41219,
'color': 'rgba(13,35,58,1)'
}, {
'name': 'Americas',
'value': 52976,
'color': 'rgba(47,126,216,1)'
}, {
'name': 'Australia',
'value': 41219,
'color': 'rgba(13,35,58,1)'
}],
legendType: 'point',
showInLegend: true
}]
});
});
highcharts
add a comment |
I would like to link a pair of areas to a legend in highcharts treemap so that clicking on the legend turns both the area on/off.
For example, in this fiddle, if I click 'America' in the legend I would like it to turn off both the areas covering 'America' & similarly to do with 'Australia'.
Fiddle here.
$(function() {
var H = Highcharts;
H.addEvent(H.Legend, 'afterGetAllItems', function(e) {
e.allItems.splice(1, 2);
});
$('#container').highcharts({
chart: {
type: 'treemap'
},
plotOptions: {
series: {
events: {
legendItemClick: function (event) {
alert('Done');
}
}
}
},
series: [{
data: [{
'name': 'Americas',
'value': 52976,
'color': 'rgba(47,126,216,1)'
}, {
'name': 'Australia',
'value': 41219,
'color': 'rgba(13,35,58,1)'
}, {
'name': 'Americas',
'value': 52976,
'color': 'rgba(47,126,216,1)'
}, {
'name': 'Australia',
'value': 41219,
'color': 'rgba(13,35,58,1)'
}],
legendType: 'point',
showInLegend: true
}]
});
});
highcharts
I would like to link a pair of areas to a legend in highcharts treemap so that clicking on the legend turns both the area on/off.
For example, in this fiddle, if I click 'America' in the legend I would like it to turn off both the areas covering 'America' & similarly to do with 'Australia'.
Fiddle here.
$(function() {
var H = Highcharts;
H.addEvent(H.Legend, 'afterGetAllItems', function(e) {
e.allItems.splice(1, 2);
});
$('#container').highcharts({
chart: {
type: 'treemap'
},
plotOptions: {
series: {
events: {
legendItemClick: function (event) {
alert('Done');
}
}
}
},
series: [{
data: [{
'name': 'Americas',
'value': 52976,
'color': 'rgba(47,126,216,1)'
}, {
'name': 'Australia',
'value': 41219,
'color': 'rgba(13,35,58,1)'
}, {
'name': 'Americas',
'value': 52976,
'color': 'rgba(47,126,216,1)'
}, {
'name': 'Australia',
'value': 41219,
'color': 'rgba(13,35,58,1)'
}],
legendType: 'point',
showInLegend: true
}]
});
});
highcharts
highcharts
asked Nov 20 '18 at 9:15
Lokesh KumarLokesh Kumar
82
82
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use point legendItemClick
event and internal setVisible
method:
plotOptions: {
series: {
point: {
events: {
legendItemClick: function(event) {
var points = this.series.points;
points.forEach(function(p) {
if (this !== p && this.name === p.name) {
p.setVisible(!this.visible, true);
}
}, this);
}
}
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/k4o8q6du/
Thanks this works! Anyway is it possible to achieve same with different charts. I have two identical charts with same legends & I want to link the legend click actions between the charts if the node has same name. Consider above example instead of duplicate 'America' & 'Australia' in the same chart, I have 2 different charts with same 'America' & 'Australia' node & Clicking on 'America' legend should ON/OFF the node in both the charts.
– Lokesh Kumar
Nov 21 '18 at 6:27
Yes, this is possible. Please see this example: jsfiddle.net/BlackLabel/1yhmt3s0
– ppotaczek
Nov 21 '18 at 11:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389690%2fhighcharts-treemap-link-legends%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use point legendItemClick
event and internal setVisible
method:
plotOptions: {
series: {
point: {
events: {
legendItemClick: function(event) {
var points = this.series.points;
points.forEach(function(p) {
if (this !== p && this.name === p.name) {
p.setVisible(!this.visible, true);
}
}, this);
}
}
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/k4o8q6du/
Thanks this works! Anyway is it possible to achieve same with different charts. I have two identical charts with same legends & I want to link the legend click actions between the charts if the node has same name. Consider above example instead of duplicate 'America' & 'Australia' in the same chart, I have 2 different charts with same 'America' & 'Australia' node & Clicking on 'America' legend should ON/OFF the node in both the charts.
– Lokesh Kumar
Nov 21 '18 at 6:27
Yes, this is possible. Please see this example: jsfiddle.net/BlackLabel/1yhmt3s0
– ppotaczek
Nov 21 '18 at 11:08
add a comment |
You can use point legendItemClick
event and internal setVisible
method:
plotOptions: {
series: {
point: {
events: {
legendItemClick: function(event) {
var points = this.series.points;
points.forEach(function(p) {
if (this !== p && this.name === p.name) {
p.setVisible(!this.visible, true);
}
}, this);
}
}
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/k4o8q6du/
Thanks this works! Anyway is it possible to achieve same with different charts. I have two identical charts with same legends & I want to link the legend click actions between the charts if the node has same name. Consider above example instead of duplicate 'America' & 'Australia' in the same chart, I have 2 different charts with same 'America' & 'Australia' node & Clicking on 'America' legend should ON/OFF the node in both the charts.
– Lokesh Kumar
Nov 21 '18 at 6:27
Yes, this is possible. Please see this example: jsfiddle.net/BlackLabel/1yhmt3s0
– ppotaczek
Nov 21 '18 at 11:08
add a comment |
You can use point legendItemClick
event and internal setVisible
method:
plotOptions: {
series: {
point: {
events: {
legendItemClick: function(event) {
var points = this.series.points;
points.forEach(function(p) {
if (this !== p && this.name === p.name) {
p.setVisible(!this.visible, true);
}
}, this);
}
}
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/k4o8q6du/
You can use point legendItemClick
event and internal setVisible
method:
plotOptions: {
series: {
point: {
events: {
legendItemClick: function(event) {
var points = this.series.points;
points.forEach(function(p) {
if (this !== p && this.name === p.name) {
p.setVisible(!this.visible, true);
}
}, this);
}
}
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/k4o8q6du/
answered Nov 20 '18 at 11:35
ppotaczekppotaczek
5,8161210
5,8161210
Thanks this works! Anyway is it possible to achieve same with different charts. I have two identical charts with same legends & I want to link the legend click actions between the charts if the node has same name. Consider above example instead of duplicate 'America' & 'Australia' in the same chart, I have 2 different charts with same 'America' & 'Australia' node & Clicking on 'America' legend should ON/OFF the node in both the charts.
– Lokesh Kumar
Nov 21 '18 at 6:27
Yes, this is possible. Please see this example: jsfiddle.net/BlackLabel/1yhmt3s0
– ppotaczek
Nov 21 '18 at 11:08
add a comment |
Thanks this works! Anyway is it possible to achieve same with different charts. I have two identical charts with same legends & I want to link the legend click actions between the charts if the node has same name. Consider above example instead of duplicate 'America' & 'Australia' in the same chart, I have 2 different charts with same 'America' & 'Australia' node & Clicking on 'America' legend should ON/OFF the node in both the charts.
– Lokesh Kumar
Nov 21 '18 at 6:27
Yes, this is possible. Please see this example: jsfiddle.net/BlackLabel/1yhmt3s0
– ppotaczek
Nov 21 '18 at 11:08
Thanks this works! Anyway is it possible to achieve same with different charts. I have two identical charts with same legends & I want to link the legend click actions between the charts if the node has same name. Consider above example instead of duplicate 'America' & 'Australia' in the same chart, I have 2 different charts with same 'America' & 'Australia' node & Clicking on 'America' legend should ON/OFF the node in both the charts.
– Lokesh Kumar
Nov 21 '18 at 6:27
Thanks this works! Anyway is it possible to achieve same with different charts. I have two identical charts with same legends & I want to link the legend click actions between the charts if the node has same name. Consider above example instead of duplicate 'America' & 'Australia' in the same chart, I have 2 different charts with same 'America' & 'Australia' node & Clicking on 'America' legend should ON/OFF the node in both the charts.
– Lokesh Kumar
Nov 21 '18 at 6:27
Yes, this is possible. Please see this example: jsfiddle.net/BlackLabel/1yhmt3s0
– ppotaczek
Nov 21 '18 at 11:08
Yes, this is possible. Please see this example: jsfiddle.net/BlackLabel/1yhmt3s0
– ppotaczek
Nov 21 '18 at 11:08
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389690%2fhighcharts-treemap-link-legends%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown