Setting width and height(设置宽度和高度)
问题描述
我正在尝试 Chart.js 的示例代码 given在文档中.
I'm trying out the example code for Chart.js given in the docs.
在 400px/400px 的画布元素上内联指定宽度和高度.
Width and height is specified inline on the canvas element at 400px/400px.
但在渲染图表时,它会被放大到整个页面宽度,并切断最右端.
But when rendering the chart it's blown up to full page width, and cuts off the far right end.
我应该如何/在哪里控制图表的宽度/高度?
How/where am I supposed to control the width/height of the chart?
推荐答案
可以覆盖画布样式宽度!important ...
You can override the canvas style width !important ...
canvas{
width:1000px !important;
height:600px !important;
}
还有
在选项下指定 responsive:true,
属性..
specify responsive:true,
property under options..
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
更新选项下添加:maintainAspectRatio: false,
链接:http://codepen.io/theConstructor/pen/KMpqvo
这篇关于设置宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:设置宽度和高度


基础教程推荐
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01