javascript - Chart.js 条形厚度

标签 javascript html jquery chart.js chart.jsv3

我需要使用 Chart.js v3.5 有关条形厚度的帮助 问题:我设置了条形厚度“barThickness:55,”,在响应式之后我不知道如何在响应式中管理它 这是我使用过的代码,请让我知道我应该为解决方案做什么。谢谢。

这里我遇到了响应式创建的问题,请查看图像网址:image link

var myNewChartB = new Chart(ctx, {
            type: "bar",
            data: barData,
            options: {
                borderSkipped: false,
                borderRadius: 3,
                plugins: {
                    barRoundness: 1,
                    legend: {
                        display: false,
                    },
                    title: {
                        font: {
                            size: 16
                        },
                        display: true,
                        text: 'Researchers (n=3)',
                        padding: {
                            left: 0,
                            right: 0,
                            top: 0,
                            bottom: 0
                        }
                    },
                    datalabels: {
                        display: true,
                        clamp: true,
                        formatter: (val, context) => (`${val}%`),
                        anchor: 'start',
                        align: 'end',
                    }
                },
    
                responsive: true,
                tooltips: {
                    enabled: false,
                },
                barThickness: 55,
                maintainAspectRatio: false,
    
                scales: {
                    x: {
                        display: true,
                        title: {
                            font: {
                                size: 16,
                            },
                            display: true,
                            text: "Scroes (1-9)",
                        },
                        grid: {
                            display: false,
                            drawBorder: false, //<- set this
                        },
                    },
                    y: {
                        display: true,
    
                        ticks: {
                            display: false
                        },
                        title: {
                            font: {
                                size: 16
                            },
                            display: true,
                            text: "% of Respondants",
                        },
                        grid: {
                            color: '#9B9898',
                            drawBorder: false, //<- set this
                        },
                    },
                },
            },
        });

最佳答案

在 Chart.js 4+ 中

我们可以使用 barPercentage 来控制条形厚度

像这样:

常量选项 = { 条形百分比:0.3, };

关于javascript - Chart.js 条形厚度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71438456/

相关文章:

html - 错误消息更改所有 block 的宽度。如何解决?

javascript - 何时使用textContent和value?

javascript - "Backbone.Model.extend() is not a function",我做错了什么?

html - 在动态文章文本中 float 一个 Div

javascript - 如何在 html/javascript 中使用 dom 检索图像的大小?

javascript - 忽略 if 语句的 PHP 函数

php - 将请求的ID发送到PHP

jquery - 获取下一个连续 div 的子级

javascript - 对于空对象给出 TypeError : Cannot convert undefined or null to object

javascript - 摆脱 "PageMap asked for range which it does not have"异常