【发布时间】:2016-11-21 15:12:02
【问题描述】:
我正在使用带有以下 html 的 Chart.js:
<canvas id="fisheye" width="100" height="100" style="border:1px solid;"></canvas>
这是 Javascript 部分:
getChart: function () {
var ctx = document.getElementById("fisheye");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["json1", "json2", "json3", "json4"],
datasets: [{
label: '1.3.0 Version',
type: 'bar',
data: [52.4060092977, 90.0854057722, 196.576968515, 77.6216726434],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(255, 99, 132, 0.2)',
'rgba(255, 99, 132, 0.2)',
'rgba(255, 99, 132, 0.2)'
// 'rgba(54, 162, 235, 0.2)',
// 'rgba(255, 206, 86, 0.2)',
// 'rgba(75, 192, 192, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(255,99,132,1)',
'rgba(255,99,132,1)',
'rgba(255,99,132,1)'
// 'rgba(54, 162, 235, 1)',
// 'rgba(255, 206, 86, 1)',
// 'rgba(75, 192, 192, 1)'
],
borderWidth: 1
},
{
label: '1.3.13 Version',
type: 'bar',
data: [50.0744953192, 93.5542439586, 153.288788005, 101.402897964],
backgroundColor: [
'rgba(54, 162, 235, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(54, 162, 235, 0.2)'
// 'rgba(255, 206, 86, 0.2)',
// 'rgba(75, 192, 192, 0.2)',
// 'rgba(153, 102, 255, 0.2)'
],
borderColor: [
'rgba(54, 162, 235, 1)',
'rgba(54, 162, 235, 1)',
'rgba(54, 162, 235, 1)',
'rgba(54, 162, 235, 1)'
// 'rgba(255, 206, 86, 1)',
// 'rgba(75, 192, 192, 1)',
// 'rgba(153, 102, 255, 1)'
],
borderWidth: 1
}
]
},
options: {
title: {
display: true,
text: 'Export Chart'
},
legend: {
display: true,
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
stepSize:50
}
}]
},
responsive: true
}
});
return myChart;
}
我的问题是我的图表似乎扩展到全屏高度和宽度。 我想将我的图表大小限制为画布大小。这样我可以在网格中而不是每页中放置图表 (注意:我只展示了一张图表的代码,但你可以想象它与其他图表类似)
【问题讨论】:
标签: javascript html canvas chart.js