在vuechart.js Horizo​​ntalBar中将默认值设置为0

时间:2019-04-25 14:22:56

标签: vue.js chart.js vue-chartjs

我正在制作vuechart.js水平条形图,并且我希望最小值/默认值设置为0。但是,我是菜鸟。所以我不知道我是否在编码“选项”。我尝试了几件事,但似乎对斧头没有任何影响。

我的最新尝试:

export default ({
extends: HorizontalBar,
props: ['agentTickets', 'options'],
mounted() {
    this.renderChart({
        labels: ['Ferry', 'Carlo', 'Menno', 'Scott'],   
        datasets: [{
            label: 'Yeet', backgroundColor: 'black', data: [10, 20, 30, 40]
        }]     
    }, 
    {
        responsive: true, maintainAspectRatio: false
    },
    {
        scales: {
        xAxes: [{
            ticks: {
                beginAtZero: true,
            },
            stacked: true
        }],
        yAxes: [{
            ticks: {
                beginAtZero: true,
            },
            stacked: true
        }]
        },
    })
}    
})

我的另一尝试:

export default {
extends: HorizontalBar,
props: ['agentTickets', 'options'],
mounted() {
    this.renderChart({
        labels: ['Ferry', 'Carlo', 'Menno', 'Scott'],   
        scales: {
                xAxes: [{
                    ticks: {
                        beginAtZero: true,
                    },
                    stacked: true
                }],
                yAxes: [{
                    ticks: {
                        beginAtZero: true,
                    },
                    stacked: true
                }]
        },
        datasets: [
            {label: 'Yeet', backColor: 'black', data: [10, 20, 30, 40]}
        ]     
    }, {responsive: true, maintainAspectRatio: false})

}    
}

还有一个是因为!

export default {
extends: HorizontalBar,
props: ['agentTickets', 'options'],
mounted() {
    this.renderChart({
        labels: ['Ferry', 'Carlo', 'Menno', 'Scott'],   
        options: {
            scale: {
                xAxes: [{
                    ticks: {
                        min: 0,
                    },
                    stacked: true
                }],
                yAxes: [{
                    ticks: {
                        min: 0,
                    },
                    stacked: true
                }]
            }
        },
        datasets: [
            {label: 'Yeet', backdropColor: 'black', data: [10, 20, 30, 40]}
        ]     
    }, {responsive: true, maintainAspectRatio: false})

}    
}

(我也尝试过使用beginAtZero的最新示例)

enter image description here

上面是当前结果,我想要的是一个从0开始而不是10的图形。

1 个答案:

答案 0 :(得分:0)

已修复。显然,这些选项已创建(已定义响应和maintenanceAspectRatio)。只需在那些花括号之间复制秤,就可以了!