How to set width of bar dynamically in chart.js?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-26 10:19:31

问题


for one value the bar width is width of canvas so i want only to change the width of bar

how to fix the width of bar size ?


回答1:


Check this out

barThickness

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
          }]
    }
});

I made this example for you



来源:https://stackoverflow.com/questions/48906453/how-to-set-width-of-bar-dynamically-in-chart-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!