我无法更改 Canvas 的高度和宽度。似乎我的图表的 javascript 渲染被覆盖了。
这是我的 HTML 代码
<body>
<canvas id="chartJSContainer" width="100" height="100"></canvas>
</body>
JS 代码
var options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [
{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1,
backgroundColor: 'rgba(255, 0, 15, 0.54)'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderWidth: 1
}
]
},
options: {
scales: {
yAxes: [{
ticks: {
reverse: false
}
}]
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
CSS 代码
canvas { background-color : #eee;
width: 100 !important;
height: 100 !important;
}
这是我的 Fiddle正如你所看到的,我什至试图通过 css 覆盖高度和宽度。
最佳答案
您的 CSS 没有单位。使用 100px !important;
或 100% !important;
等。
关于javascript - 尝试更改图表 Canvas 的高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60791337/