reactjs - Highcharts 使用拖动/调整大小 react-rnd 库自动调整大小
问题描述
我想创建一个组件,其中图表的大小会随着保存图表的容器的调整大小事件自动调整。如果有人可以帮助我举个例子,那就太好了。这里是图书馆的链接。react-rnd 库
Ex somehting like this but using highcharts codebox react-rnd with googlecharts
const Highchart = () => {
return (
<rnd>
<div>
<HightchartsReact highcharts={Highcharts} constructorType={'chart'} options={option} />
</div>
</rnd>
)
}
解决方案
您需要在事件回调函数中调用chart.reflow
方法。onResizeStop
return (
<Rnd
...
onResizeStop={(e, direction, ref, delta, position) => {
const chart = this.chartComponent.current?.chart;
if (chart) {
chart.reflow();
}
...
}}
>
...
</Rnd>
);
来自 Highcharts API:
回流([e])
将图表重排到其容器。默认情况下,根据 chart.reflow 选项,在 window.resize 事件之后,图表会自动回流到其容器。但是,对于 div 调整大小没有可靠的事件,因此如果在没有窗口调整大小事件的情况下调整容器大小,则必须显式调用。
现场演示: https ://codesandbox.io/s/cranky-hoover-cz-czw5k?file=/src/index.js
API 参考: https ://api.highcharts.com/class-reference/Highcharts.Chart#reflow
推荐阅读
- javascript - firebase reauthenticateAndRetrieveDataWithCredential facebook 用户凭据
- reactjs - 为什么 redux 状态没有映射到反应状态?
- java - Java Doc Transformer 重新排列 xml
- c - 数组超过大约 255000 int 时出现分段错误
- vb.net - 在 vb.net 中获取进程的基地址
- date - 如何处理星期几调整
- javascript - Express Middleware 似乎没有进入下一个路由
- c++ - 将 2 字节数分成两个 1 字节
- vb.net - 将 ookii 对话框添加到 Sharpdevelop VB.NET 项目中
- java - 从 sftp 读取 tar 文件并在运行中将其转换为 hdfs 上的 gzip