Chart.js条形图:如何删除v2.3中栏之间的空格? [英] Chart.js Bar Chart: How to remove space between the bars in v2.3?

查看:85
本文介绍了Chart.js条形图:如何删除v2.3中栏之间的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除条形图条之间的空间,但即使我看到这个解决方案很多地方也不适用于我。它在Chart.js文档中也没有提到,所以这很奇怪。有人可以告诉我如何指定吗?

I'm trying to remove the space between my bar chart bars, but even though I see this solution many places it doesn't work for me. It's also not mentioned in the Chart.js docs so that is odd. Can someone tell me how to specify it?

var options = {
    barValueSpacing : 1,        // doesn't work; find another way
    barDatasetSpacing : 1,      // doesn't work; find another way

    legend: {
        display: false          // Hides annoying dataset label
    },
    tooltips: {
        callbacks: {
            label: function(tooltipItem) {
                return tooltipItem.yLabel;
            }
        }
    }
};

var ctx = document.getElementById("canvasX").getContext("2d");          
var myBarChart = new Chart(ctx, {
    type: 'bar',
    data: data,
    options: options
});


推荐答案

您需要设置 barPercentage x轴刻度上的 categoryPercentage 1.0 。将其添加到选项对象:

You need to set barPercentage and categoryPercentage to 1.0 on the x-axis scale. Add this to your options object:

var options = {
    ...
    scales: {
        xAxes: [{
            categoryPercentage: 1.0,
            barPercentage: 1.0
        }]
    }
};

参见 http://www.chartjs.org/docs/#bar-chart-chart-options

这篇关于Chart.js条形图:如何删除v2.3中栏之间的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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