I'm using a highmaps worldmap, and when I hover on a country I want the tooltip to list out all of the food chains that are from that specific country. However I'm only managing to get the tooltip to list out the first result. The number of results for each country vary.
For example, I want the tooltip to list out the following food chains when hovering on the US:
1: {companyName: “Burger King“, hc-key: "us"}
2: {companyName: “McDonalds”, hc-key: "us"}
3: {companyName: “Kentucky Fried Chicken”, hc-key: "us"}
4: {companyName: “Quiznos”, hc-key: "us"}
5: {companyName: “Subway”, hc-key: "us"}
6: {companyName: “In and Out“, hc-key: "us"}
7: {companyName: “Taco Bell“, hc-key: "us"}
8: {companyName: “Popeyes”, hc-key: "us"}
9: {companyName: “Jack in the Box”, hc-key: "us"}
10: {companyName: “Italia Pizza”, hc-key: "it"}
10: {companyName: “Italia Pasta”, hc-key: "it"}
My current code outputs the first result, I just don't know enough to edit the tooltip formatter to account for the rest of the results. Thank you.
mapdata(Highcharts){
this.companyData
.getcompanyCountries(this.selectedIndustry)
.subscribe(
(data: any[]) => {
this.companies = data.map(function(el){
return {companyName: el.name, 'hc-key':el.country_code}
})
console.log(this.companies)
// Create the chart
Highcharts.mapChart('container-map', {
chart: {
map: worldMap,
},
title: {
text: ''
},
legend: {
enabled: false
},
mapNavigation: {
enabled: false,
buttonOptions: {
alignTo: 'spacingBox'
}
},
series: [{
color: '#ffff00',
nullborderColor: '#d3d3d3',
type: 'map',
name: 'Food Chains',
tooltip: {
pointFormat: '{point.name}:<br><b>{point.companyName}',
},
states: {
hover: {
color: '#ffff00'
}
},
dataLabels: {
enabled: false,
format: ''
},
nullColor: 'white',
allAreas: true,
joinBy: 'hc-key',
data: this.companies,
}]
})
}
)}
EDITED:
mapdata(Highcharts){
this.companyData
.getcompanyCountries(this.selectedIndustry)
.subscribe(
(data: any[]) => {
this.companies = data.map(function(code){
return {companyName: code.name, code: code.country_code}
})
console.log(this.companies)
// Create the chart
Highcharts.mapChart('container-map', {
chart: {
map: worldMap,
},
title: {
text: ''
},
legend: {
enabled: false
},
credits: {
enabled: false
},
mapNavigation: {
enabled: false,
buttonOptions: {
alignTo: 'spacingBox'
}
},
plotOptions: {
map: {
allAreas: true,
joinBy: ['hc-key','code'],
dataLabels: {
enabled: true,
color: '#FFFFFF',
style: {
fontWeight: 'bold'
},
// Only show dataLabels for areas with high label rank
format: null,
formatter: function() {
if (this.point.properties && this.point.properties.labelrank.toString() < 5) {
return this.point.properties['hc-key'];
}
}
},
tooltip: {
headerFormat: '',
pointFormatter: function() {
var string = '<b>' + this.name + ':<br>';
data.forEach(function(companyName) {
string += companyName.name + '<br>'
});
return string;
}
}
}
},
series: [{
color: '#ffff00',
nullborderColor: '#d3d3d3',
type: 'map',
name: 'Food Chains',
states: {
hover: {
color: '#ffff00'
}
},
dataLabels: {
enabled: false,
format: ''
},
nullColor: 'white',
data: this.companies,
}]
})
}
)}