注意:我已经修复了问题 #2,这是错误的数据。我仍然面临问题#1。
我有以下折线图配置。我的数据集示例数据是
{x:'29/01/2017',y:'0.00234'}
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
xAxes: [{
type: 'time',
time: {
format: 'DD/MM/YYYY'
}
}]
}
}
另外,我有 html(我使用 angular flex-layout)和 typescript :
<div fxFlex style="height: 100%">
<div id="graph">
<canvas id="canvasGraph">{{chart}}</canvas>
</div>
</div>
// Hoping I can change the size of canvas to be the same as the parent
const canvas = <HTMLCanvasElement>document.getElementById('canvasGraph');
canvas.width = document.getElementById('graph').offsetWidth;
canvas.height = document.getElementById('graph').offsetHeight;
我有 2 个(现在只剩下 1 个)问题:
(我更新了标题,因为我已经解决了这个问题,这是由错误的数据引起的)
最佳答案
我终于解决了我的问题。现在图表是响应式的。
#graph{
position: relative;
height: 100%;
width: 100% !important;
}
canvas {
width: 100% !important;
}
关于angular - chartjs 高度不跟随父容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51552672/