Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts reflow is not updating Highcharts container width

Highcharts container is not updating it's width

So, as you can see I'm trying to reflow Highcharts in order to keep the right width according to it's parent container, in order to do that I'm listening to the sidebar state and calling reflow whenever the state is changed.

useEffect(() => {
   Highcharts.charts[0].reflow();
}, [collapseSideBar]);

This is my Highcharts component:

<div className="text-black-50 col-span-2 row-span-2 bg-white rounded-lg shadow-xl h-100 w-100">
    <HighchartsReact highcharts={Highcharts} options={a11Options} />
</div>
like image 905
Pedro Luiz Santos Avatar asked Nov 30 '25 20:11

Pedro Luiz Santos


1 Answers

You might try postpone the execution of the reflow method after the sidebar animation ends. Or, if more convenient, try set a timeout as follows:

useEffect(() => {
   setTimeout(function() {
      Highcharts.charts[0].reflow();
   }, 300);
}, [collapseSideBar]);

Remember to change the 300 value to the animation time delta.

This happens due to width from elements in DOM updates after the animation runs, for performance reasons. During the animation, there is probably some transform CSS rules in the making.

like image 91
theWhK Avatar answered Dec 03 '25 11:12

theWhK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!