简体   繁体   中英

ChartJS align bars to left instead of center

I have a relatively simple bar chart in my application.

在此处输入图片说明

Code:

    new Chart(document.getElementById("foo"), {
        type: "bar",
        options: {
            scales: {
                yAxes: [{
                    display: false,
                }],
                xAxes: [{
                    display: false,
                }]
            },
            elements: {
                bar: {
                    borderWidth: 2,
                    borderColor: "#D2DDEC"
                },
                point: {
                    hoverRadius: 0
                },
            },
            legend: {
                display: false,
            },
        },
        data: {
            labels: Object.keys(values),
            datasets: [{
                data: Object.values(values),
            }]
        }
    })

However, these bars will center in the middle of the container, while I would like these to start left. Is there a way to do this? I don't see any align property in the API.

我刚刚添加了标签,直到我达到 31。已修复。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM