Search code examples
javascripthighchartstreemap

Different tooltip and value in Treemap || Highcharts


I am currently displaying a treemap with lot to data and hence due to huge values some tiles are taking more space compared to others.

So, I wanted to do a log of value and show actual value in tooltip.

But currently, i am give the tooltip from value attribute only.

Please suggest how to give tooltip as well as value simultaneously.


Solution

  • By using tooltip.formatter function you are able to create any tooltip format, for example:

        tooltip: {
            formatter: function() {
                var str = this.point.name + ' ' + this.point.value,
                    node = this.point.node;
    
                if (node) {
                    node.children.forEach(function(child) {
                        str += '<br />' + child.name + ' ' + child.val;
                    });
                }
    
                return str;
            }
        }
    

    Live demo: https://jsfiddle.net/BlackLabel/z5rdh83p/

    API Reference: https://api.highcharts.com/highcharts/tooltip.formatter