Is modifying chart.hasUserSize a bad idea after ca

2019-01-28 17:47发布

问题:

When using Chart.setSize() I've noticed that the value chart.hasUserSize gets set to true. Once hasUserSize = true the chart will no longer respond to resize events if the window changes dimensions however if you set hasUserSize back to false it again responds to resize events.

I've created a UX that allows the user to "expand" the chart container to 100% width however once I've called setSize() it no longer auto resizes until I remove the hasUserSize=true value.

Since it's not a documented part of the API should this be considered a hack? The problem is I don't see a documented way to re-enable the resizing code natively in Highcharts once you've called setSize().

It's working exactly as I want it to right now but I don't want to leave a wart in the code that may come back to bite me in future versions of Highcharts.

http://jsfiddle.net/FZCNk/

chart.hasUserSize = false

Here's a jsfiddle that, when the window is resized, demonstrates what I'm talking about with the included "hack". Resize the window/chart pane before clicking anything, then click a size button and resize and it'll respond on the width. Comment out the "chart.hasUserSize = false" lines and try resizing. It's not a perfect example but it gets the point across with my use of hasUserSize = false.

Is it the right thing to do to reclaim the sizing behavior after calling setSize()?

标签: highcharts