如何在chart.js中动态设置条形图的宽度?

9njqaruj  于 2022-11-06  发布在  Chart.js
关注(0)|答案(2)|浏览(358)

for one value the bar width is width of canvas so i want only to change the width of bar
如何确定条形尺寸的宽度?

jfgube3f

jfgube3f1#

Check this out

barThickness

手动设置每个条形的宽度(以像素为单位)。如果未设置,则自动计算基本样本宽度,以便它们采用全部可用宽度而不重叠。然后,使用barPercentage和categoryPercentage调整条形的大小。
您的代码应该如下所示:

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

I made this example for you

rryofs0p

rryofs0p2#

溶液

您可以在Chart对象上设置它

import {Chart} from "chart.js"

Chart.defaults.datasets.bar.barThickness = 73;

//also try barPercentage, maxBarThickness

相关问题