[英]Chart.js: How to set minimum height of chart but still maintain aspect ratio?
How can I set a fixed aspect ratio to the chart but also set a minimum height so that it behaves like below:如何为图表设置固定的纵横比,但还要设置最小高度,使其表现如下:
I have tried using react-chartjs-2
:我曾尝试使用react-chartjs-2
:
<div
style={{
minHeight: 300,
paddingTop: "33.33333%",
}}
>
<Bar
style={{ width: "100%", height: "100%" }}
//data={...}
options={{
maintainAspectRatio: false,
}}
/>
</div>
Solved it by adding an intermediate div between container and chart:通过在容器和图表之间添加一个中间 div 来解决它:
<div
style={{
minHeight: 300,
paddingTop: "33.33333%",
position: "relative",
}}
>
<div
style={{
position: "absolute",
inset: 0,
}}
>
<Bar
style={{ width: "100%", height: "100%" }}
//data={...}
options={{
maintainAspectRatio: false,
}}
/>
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.