0

How can I add custom data to my map series?

Currently, the custom data is an array-like object data: [string, number][] and its values look like: [["us",0],["uk",0],...].

Also it looks like the data is joinBy: ["hc-key", "hc-key"] but I cannot even access hc-key in the tooltip:

tooltip: {
        headerFormat: '',
        formatter: function () {
            const country = this.point;
            console.log(this);
    // cannot access this['hc-key'] or country['hc-key']
            const info = `The value for ${country.name} is ${country.value}`
            return info;
        }
    },
// I also filter country by value like this:
colorAxis: {
        dataClasses: [
            {
                from: 0,
                to: 0,
                color: "#9E9E9E",
                name: 'No Data'
            }, 

How can I make the series to take in a data structure like this instead of the array [[],[],...]:

[
  {country: 'us', name: 'USA', some_value: 0, some_other_values: [{...},{...},...],...},
...
]

so I can display more information in the tooltip but still be able to style each country by its some_value?

I've looked at the answers like here and here but they don't work for me.

I'm working with the code from this example here.

1 Answer 1

1

I prepared a very simple demo example which shows how to create data which will fill your requirements.

Demo: https://jsfiddle.net/BlackLabel/yv5fp80o/

The data:

var data = [{
  'hc-key': 'in',
  value: 20,
  customValue: [10, 20]
}]

The custom value could be shown in the tooltip by using the formatter feature: https://api.highcharts.com/highcharts/tooltip.formatter

And here is a way how to get the full array of mapData where you can find a hc-key for wanted countries.

console.log(chart.series[0].mapData)
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Sebastian! Let me try it and get back to you.
Sure, we can continue this thread here or in case of a new issue start a new topic.
Thank you. Your answer was what I was looking for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.