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
这篇关于设置宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:设置宽度和高度


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01