3
我有问题可以让chart.js折线图对高度和宽度做出响应。Chart.js不是高度响应
见例如它应当那样: http://www.chartjs.org/samples/latest/charts/line/basic.html
这里是我的代码:
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
var lineChartData = {
labels : ['January','February','March','April','May','June','July'],
datasets : [
{
label: 'My First dataset',
labelColor : '#fff',
fontColor : '#fff' ,
backgroundColor : 'rgba(220,220,220,0.2)',
borderColor : 'rgba(220,220,220,1)',
pointBackgroundColor : 'rgba(220,220,220,1)',
pointBorderColor : '#fff',
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
}
]
}
var options = {
maintainAspectRatio: false,
legend: {
display: false,
},
scales: {
xAxes: [{
gridLines: {
display: false,
color: '#03A5C5',
lineWidth: 8,
},
ticks: {
fontColor: "white",
},
}],
yAxes: [{
gridLines: {
display: false,
color: '#03A5C5',
lineWidth: 8,
},
ticks: {
fontColor: "white",
beginAtZero: true,
}
}]
}
};
var ctx = document.getElementById('canvas-1');
var chart = new Chart(ctx, {
responsive: true,
type: 'line',
data: lineChartData,
options: options
});
他们说在[文档](HTTP://www.chartjs。 org/docs/latest/general/responsive.html)图表有麻烦与响应。希望你会找到解决方案,因为我不能 – blewherself
在文档中,他们建议将canvas标签包装到容器div中,并将其设置为自己的宽度和高度。基本上这就是你在他们提到的响应式expample中所做的。它有助于解决你的情况? – blewherself
@blewherself它的工作!谢谢 –