如何在chart.js中动态设置条的宽度? [英] How to set width of bar dynamically in chart.js?

查看:383
本文介绍了如何在chart.js中动态设置条的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个值,条的宽度是画布的宽度,所以我只想更改bar

如何确定条形尺寸的宽度?

how to fix the width of bar size ?

推荐答案

看看

barThickness




以像素为单位手动设置每个条的宽度。如果未设置,则将自动计算基本样本
的宽度,以使它们获取完整的
可用宽度而不会重叠。然后,使用
barPercentage和categoryPercentage调整条的大小。

Manually set width of each bar in pixels. If not set, the base sample widths are calculated automatically so that they take the full available widths without overlap. Then, the bars are sized using barPercentage and categoryPercentage.

您的代码应该是这样的:

Your code should be something like this:

var myBarChart = new Chart(ctx, {
    type: 'bar',
    data: data,
    options: {
       scales: {
          xAxes: [{
             barThickness: 10
          }]
    }
});

我为您制作了此示例

这篇关于如何在chart.js中动态设置条的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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