shinjune2
Posts: 12
Joined: Sat May 15, 2021 2:44 pm

Dynamic fontSize of dataLabels in treemap chart

I'd like to resize the fontSize of dataLabels dynamically depending on the value.

For example, the dataLabel fontSize of AAPL should be much larger than current size.

I tried to 'formatter' and callback function but it doesn't read the 'point'.

Can you help me what I have to do?

Image

Code: Select all

series: [{
        data: treemapData,
        type: 'treemap',
          levels: [{
            level: 1,
            dataLabels: {
              style: {
                fontSize: '15px',
              },
              format: '{point.name}'
            }
          },{
          level: 2,
          dataLabels: {
            formatter: function() {
              return adjustTextPosition(this.point);
            },
            style: {
              fontSize: {
                formatter: function(){
                  return adjustTextSize(this.point)
                }
              }
            },
          }
        }],
        
 

Code: Select all

  const adjustTextPosition = (point) => { 
      const width = point.shapeArgs.width;
      const height = point.shapeArgs.height;
        if(width + height > 200) {
          return `${point.name}`
        }
    }

Code: Select all

 const adjustTextSize = (point) => {
       
       const width = point.shapeArgs.width;
       const height = point.shapeArgs.height;
      
        if(width + height > 200) {
          return  point.series.options.dataLabels.style.fontSize == '30'

        }
    }

Attachments
Screen Shot 2021-11-22 at 00.04.59.png
Screen Shot 2021-11-22 at 00.04.59.png (50.3 KiB) Viewed 282 times
shinjune2
Posts: 12
Joined: Sat May 15, 2021 2:44 pm

Re: Dynamic fontSize of dataLabels in treemap chart

Is there anyone who can help me? TT
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Dynamic fontSize of dataLabels in treemap chart

Hello shinjune2,

We're already preparing an answer for your questions. Our work time doesn't include weekends so please be patient and you will receive your answer asap.

Regards!
Mateusz Bernacik
Highcharts Developer
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: Dynamic fontSize of dataLabels in treemap chart

shinjune2,

We don't have such functionality implemented in Highcharts, you need to code it on your own. Please check thoroughly this topic, you'll find there solution for this problem and many useful related information: viewtopic.php?t=47208&p=169829
You'll learn also about drawbacks of suggested approach.

Let me know if that was what you were looking for.
Regards!
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Usage”