设置宽度和高度 [英] Setting width and height

查看:32
本文介绍了设置宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试 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

这篇关于设置宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆