ChartJS 图表js 3.9.1 -条形图-左边距

vc9ivgsu  于 2022-12-23  发布在  Chart.js
关注(0)|答案(1)|浏览(173)

我如何减少条和y刻度之间的空间?我试过填充,但不起作用
谢啦,谢啦

这是我的配置,我在运行时上载数据并更新图表
图表寄存器(图表数据标签);

var options = {
    tooltips: {
        enabled: false
    },
    plugins:
    {
        datalabels:
        {
            color: 'white'
        },
        legend: {
            position: 'top', labels:
            {
                font: {size: 10},
                usePointStyle: true
            }
        }
    },
    scales:
    {
        x: {
            barPercentage: 6.5,
            categoryPercentage: 0.1
        },
        y: {
            barPercentage: 1,
            categoryPercentage: 1,
            beginAtZero: true,
            grace: '3%',
            ticks: {
                beginAtZero: true
            }
        }
    }
};

var barChart = new Chart(document.getElementById("chart3"), {
    type: 'bar',
    data:
    {
        labels: [""]
    },
    options:options
});

for (i = 0; i < parsed[0].length; i++)
{
    barChart.data.datasets.push({ label: parsed[0][i].label, backgroundColor: parsed[0][i].backgroundColor, data: ["" + parsed[0][i].data + ""], pointStyle:'circle' });
}

barChart.update();
l3zydbqr

l3zydbqr1#

这个问题听起来与您在轴中设置的categoryPercentagebarPercentage选项有关,但这不是正确的位置。
chart.options中移动这些选项,它应该可以工作。
尝试使用categoryPercentage: 1

var options = {
    categoryPercentage: 1,
    plugins:
    {
        datalabels:
        {
            color: 'white'
        },
        legend: {
            position: 'top', labels:
            {
                font: {size: 10},
                usePointStyle: true
            }
        }
        tooltip: {
            enabled: false
       },
    },
    scales:
    {
        y: {
            beginAtZero: true,
            grace: '3%',
        }
    }
};

相关问题