ArticleZip > Chart Js Axes Label Font Size

Chart Js Axes Label Font Size

Chart.js is a powerful tool for creating interactive and visually appealing charts on the web. One common functionality that developers often want to customize is the font size of axes labels on the charts. In this guide, we will walk you through how to adjust the font size of axes labels in Chart.js to better suit your project's needs.

To begin, first, make sure you have the Chart.js library included in your project. You can either download the library and link it in your HTML file or include it through a content delivery network (CDN). Once you have the library set up, you can start customizing the axes labels.

In Chart.js, axes labels are controlled through the `scales` option in the chart configuration object. Within the `scales` option, you can specify settings for both the x-axis and y-axis, including the font size of the labels.

Here is an example configuration object that demonstrates how to adjust the font size of axes labels:

Javascript

var chart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3],
            backgroundColor: [
                'red',
                'blue',
                'yellow',
                'green',
                'purple',
                'orange'
            ]
        }]
    },
    options: {
        scales: {
            x: {
                ticks: {
                    font: {
                        size: 16 // Adjust the font size here
                    }
                }
            },
            y: {
                ticks: {
                    font: {
                        size: 12 // Adjust the font size here
                    }
                }
            }
        }
    }
});

In the example above, we have set the font size of the x-axis labels to 16 and the font size of the y-axis labels to 12. You can adjust these values to your liking to achieve the desired font size for your axes labels.

Additionally, you can further customize the font styling by specifying other font properties such as `family`, `style`, and `weight` within the `font` object for more granular control over the appearance of the labels.

By following these steps, you can easily adjust the font size of axes labels in Chart.js to create charts that align with the visual style of your web application. Experiment with different font sizes and styles to find the perfect combination that enhances the readability and aesthetics of your charts. Happy coding!

×