amcharts5 icon indicating copy to clipboard operation
amcharts5 copied to clipboard

How to get the _contentHeight of a legend ?

Open justine-mlss opened this issue 2 years ago • 1 comments

Hello,

I want to retrieve the content height of a legend.

For example : https://codepen.io/Justinemlss/pen/jOzxWNZ

When i console.log legend, I can see a property named _contentHeight with the value 28. But I don't know how to retrieve this property. legend._contentHeight : doesn't work legend.get("._contentHeight") : doesn't work

In the legend documentation : https://www.amcharts.com/docs/v5/reference/legend/, there is the method height() which is supposed to Returns height of this element in pixels, but .. legend.height() returns 0 !

Can you help me please thanks

justine-mlss avatar Aug 05 '22 08:08 justine-mlss

I guess you call legend.height() without waiting for the legend to be built. You should do that on boundschanged event:

legend.events.on("boundschanged", function(){
  console.log(legend.height())  
})

This will console the real height of a legend, not only visible part. And then you can update size of your legend div: https://codepen.io/team/amcharts/pen/poLKYRy

zeroin avatar Aug 09 '22 05:08 zeroin

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

github-actions[bot] avatar Sep 09 '22 00:09 github-actions[bot]