【发布时间】:2021-05-05 13:54:33
【问题描述】:
我在容器中显示 Chart.js 图表,它们不尊重它们的大小,而是超出了它们。
在图表配置中我有:
responsive: true,
maintainAspectRatio: false,
html如下:
<div class="graph-container">
<div class="graph-wrapper">
<canvas id="myChart" class="graph-canvas" width="300" height="300"></canvas>
</div>
</div>
相应的 CSS 是:
.graph-container {
position: absolute;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background-color: $blue;
display: none;
}
.graph-wrapper {
position: relative;
height: 100vh;
width: 100vw;
display: block;
}
注意:.graph-container 上的 display: none; 在单击按钮时会发生变化。
容器以正确的大小显示,但只是被图表大大覆盖了。
任何想法将不胜感激。
谢谢
杰克
【问题讨论】:
标签: javascript html css chart.js