Width is calculated from the container element but height not
Hi @kirjs Thank you for a great component :)
As the title implies i am having a problem with the chart height. In highchart documentation it says that if width and height are not set in the config, then the chart takes the parent container size.
In the example here It works well on pure highchart http://jsfiddle.net/o1pnxfnv/
But when i use react-highchart, the height seems fixed and does not stretch to the parent div height. Example (can be edited thorugh gist if clicking on the button on the top-right) http://output.jsbin.com/gobukah
Any idea?
@omerKenshoo @omriavigdor @charliehavak
@mosheKenshoo I noticed this as well and was going to file a bug report when I got around to it. Another example of height not adjusting - https://jsfiddle.net/ktppqv0g/1/.
In the meantime, I use the following for a work around.
const parentHeight = <get via https://github.com/STRML/react-resizable or similar lib>;
const config = {
chart: {
...
height: parentHeight
}
...
};
<ReactHighstock config={config} />
@Jakehp thanks!
This has to do with the offsetHeight of a block element inside a block:
<div style="height: 200px">
<div class="highcharts-root">
<div class="highcharts-container"><!-- rendered by highcharts --></div>
</div>
</div>
The offsetHeight of .highcharts-root is 0, so according to the documentation, chart.height gets automatically set to 400px.
Note that automatic resize on container resize is outside the scope of highcharts.
Feel free to reopen (also if anyone wants to send a docs PR, would be great, maybe just mention height and link here?
does somebody can give me a solution for this problem? can't solve it...
I added an event listener on page resize that updates a height local slice of state which is used by my ReactHighStock component to determine the height. This solved the problem for me.
` componentDidMount() { window.addEventListener("resize", this.updateDimensions); this.updateDimensions(); }
updateDimensions() {
let height = this.getDims();
this.setState({
height: height
});
}
getDims() {
let navBarHeight = document.querySelector('.navbar-container').clientHeight;
let height = window.innerHeight - navBarHeight;
return(height);
}`
@STRML How to get the onResize event on GridItem as mentioned in STRML/ResizableBox
onResize = (event, {element, size}) => {
this.setState({width: size.width, height: size.height});
};
I am expecting this event in my code so, that I can re flow the highcharts in child component.
<ResponsiveReactGridLayout
breakpoints={{lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0}}
cols={{lg: 18, md: 10, sm: 6, xs: 4, xxs: 2}}
rowHeight={20}
autoSize={false}
draggableCancel="input,textarea"
useCSSTransforms={true}
// onLayoutChange={this.onLayoutChange}
// onBreakpointChange={this.onBreakpointChange}
containerPadding={[5, 5]}
margin={[10, 10]}
{...this.props}
>
{_.map((this.dashboardStore.currentDashboard.layout), el => this.createElement(el))}
</ResponsiveReactGridLayout>
In child component of I use,
<div className="visualTile" ref={(tileContainerEl) => this.tileContainerEl = tileContainerEl} >
{/* <pre>{JSON.stringify(this.props.grid, null, 1)}</pre> */}
<ReactHighcharts
config={config}
callback={this.getChart}
/>
</div>
componentDidMount() {
var height = this.tileContainerEl.clientHeight;
var width = this.tileContainerEl.clientWidth;
this.chart.setSize(width, height);
this.chart.reflow();
}
Thank you.
Hey @abelkbil , How did you prevent your "ResponsiveReactGridLayout" to trigger "onLayoutChange" when user click on grid?
@nywooz Click will not trigger, I confuse your click might have made some changes to click either by css or any.
Anyone can give me a solution for this problem? can't solve it!
I finally find a solution with the help of react-sizeme library.
npm install react-sizemeSee: https://github.com/ctrlplusb/react-sizeme- Make a wrapper component
ReactHighstockWrapper.
import cloneDeep from 'lodash/cloneDeep';
import React, { PureComponent } from 'react';
import { withSize } from 'react-sizeme';
import ReactHighstock from 'react-highcharts/ReactHighstock.src';
class ReactHighstockWrapper extends PureComponent {
render() {
const {
size: { width, height },
config,
...otherProps
} = this.props;
let newConfig = cloneDeep(config);
newConfig.chart = {
width,
height,
};
return (
<div style={{ height: '100%' }}>
<ReactHighstock config={newConfig} {...otherProps} />
</div>
);
}
}
ReactHighstockWrappercomponent will automatically extend to 100% height of its container's div.
@huangzhuolin very thanks
solution is
Config.chart = {
width:'200',
height:'200'
};
changed hight