简体   繁体   English

chart.js 从数据集标签修改样式

[英]chart.js modify style from dataset label

(hey!) I'm discovering JS and Chart.js and I need to change font size and font weight from the label in dataset but I don't find anything in documentation or on google. (嘿!)我正在发现 JS 和 Chart.js,我需要从数据集中的标签更改字体大小和字体粗细,但我在文档或谷歌上找不到任何内容。 Can anyone give me any suggestion ?任何人都可以给我任何建议吗?

import Chart from 'chart.js'

let ctx = document.getElementById('rentResumeChart').getContext('2d');

let rentResumeChart = new Chart(ctx, {
responsive: true,
maintainAspectRatio: false,
type: 'bar',
data: {
    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
    datasets: [{
        label: '# of Votes', //this one
        data: [12, 19, 3, 5, 2, 3],
        backgroundColor: [
            'rgba(255, 99, 132, 0.2)',
            'rgba(54, 162, 235, 0.2)',
            'rgba(255, 206, 86, 0.2)',
            'rgba(75, 192, 192, 0.2)',
            'rgba(153, 102, 255, 0.2)',
            'rgba(255, 159, 64, 0.2)'
        ],
        borderColor: [
            'rgba(255, 99, 132, 1)',
            'rgba(54, 162, 235, 1)',
            'rgba(255, 206, 86, 1)',
            'rgba(75, 192, 192, 1)',
            'rgba(153, 102, 255, 1)',
            'rgba(255, 159, 64, 1)'
        ],
        borderWidth: 1
    }]
},
options: {
    scales: {
        yAxes: [{
            ticks: {
                beginAtZero: true,
                fontSize: 25,
                fontStyle: 'bold'
            }
        }],
        xAxes: [{
            ticks: {
                fontSize: 25,
                fontStyle: 'bold'
            }
        }],
    },
}
});

What you need you can find here: here .你可以在这里找到你需要的东西:这里

See next example how you can use this:请参阅下一个示例如何使用它:

legend: {
    labels: {
       fontSize: 22
    }
}

Just add code in your chart options, then your code will look like:只需在您的图表选项中添加代码,您的代码将如下所示:

options: {
    legend: {
        labels: {
            fontSize: 22
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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