Skip to main content
PHP Blog

Back to all posts

How to Add Axis Titles to Chart.js Charts?

Published on
6 min read
How to Add Axis Titles to Chart.js Charts? image

Best Chart.js Axis Title Tools to Buy in October 2025

1 MORSE CUTTING TOOLS Heavy Duty Large Plastic Wall Chart - Decimal Equivalents, Recommended Drill Sizes for Taps, and Useful Formulas

MORSE CUTTING TOOLS Heavy Duty Large Plastic Wall Chart - Decimal Equivalents, Recommended Drill Sizes for Taps, and Useful Formulas

  • DURABLE HEAVY-DUTY PLASTIC RESISTS WEAR AND TEAR FOR LONG-LASTING USE.
  • VERSATILE TAP DRILL SIZES FOR INCH, METRIC, AND PIPE THREADS INCLUDED.
  • EASY WALL MOUNTING WITH THREE PUNCHED HOLES FOR QUICK INSTALLATION.
BUY & SAVE
$35.95
MORSE CUTTING TOOLS Heavy Duty Large Plastic Wall Chart - Decimal Equivalents, Recommended Drill Sizes for Taps, and Useful Formulas
2 NELOMO 11.8” X 7.9” Toolbox Reference Card Toolbox Accessories Conversion Chart Card SAE Metric Ruler Standard Metric Conversion Charts Tap Drill Sizes Wrench Conversion Chart

NELOMO 11.8” X 7.9” Toolbox Reference Card Toolbox Accessories Conversion Chart Card SAE Metric Ruler Standard Metric Conversion Charts Tap Drill Sizes Wrench Conversion Chart

  • ALL-IN-ONE REFERENCE CARD FOR QUICK CONVERSIONS AND SIZES.
  • DURABLE, LAMINATED DESIGN WITHSTANDS WEAR FOR LASTING USE.
  • PORTABLE AND VERSATILE FOR INDOOR AND OUTDOOR PROJECTS.
BUY & SAVE
$5.99
NELOMO 11.8” X 7.9” Toolbox Reference Card Toolbox Accessories Conversion Chart Card SAE Metric Ruler Standard Metric Conversion Charts Tap Drill Sizes Wrench Conversion Chart
3 HIPPOTALE Chores Chart for Kids - Daily Routine Chart for Kids with Checklist & Stickers, Magnetic Kids Chore Chart - Chore Board Visual Schedule for Kids with Autism & Best ADHD Tools for Kids

HIPPOTALE Chores Chart for Kids - Daily Routine Chart for Kids with Checklist & Stickers, Magnetic Kids Chore Chart - Chore Board Visual Schedule for Kids with Autism & Best ADHD Tools for Kids

  • CUSTOMIZABLE CARDS FOR UNIQUE CHORES, PERFECT FOR ALL FAMILY NEEDS.

  • VISUAL TASK BOARD IDEAL FOR KIDS WITH ADHD AND EASY FOR EVERYONE.

  • DURABLE, PORTABLE DESIGN WITH MAGNETIC OPTIONS FOR EASY DISPLAY.

BUY & SAVE
$11.98
HIPPOTALE Chores Chart for Kids - Daily Routine Chart for Kids with Checklist & Stickers, Magnetic Kids Chore Chart - Chore Board Visual Schedule for Kids with Autism & Best ADHD Tools for Kids
4 Large Magnetic Reward Chart for Kids - 127 Pre-Written Stickers (Including Potty Training) + 30 Customizable Chores - Behavior, Responsibility & Incentive Routine Star Chart for Fridge (1 Kid Version)

Large Magnetic Reward Chart for Kids - 127 Pre-Written Stickers (Including Potty Training) + 30 Customizable Chores - Behavior, Responsibility & Incentive Routine Star Chart for Fridge (1 Kid Version)

  • FUN & EASY FOR KIDS: ENGAGING WAY TO MOTIVATE CHILDREN WITH CHORES!

  • CUSTOMIZABLE: CREATE TASKS WITH 30 TAGS OR 127 FUN PRE-PRINTED STICKERS.

  • SECURE & ORGANIZED: STRONG MAGNETS AND STORAGE BAG KEEP STARS IN PLACE!

BUY & SAVE
$39.95
Large Magnetic Reward Chart for Kids - 127 Pre-Written Stickers (Including Potty Training) + 30 Customizable Chores - Behavior, Responsibility & Incentive Routine Star Chart for Fridge (1 Kid Version)
5 Pajean 253 Pcs Student Behavior Pocket Chart for Classroom Behavior Management Resources Track Reward Bulletin Board Customizable Class Jobs for Home Preschool Daycare Back to School Teacher Supplies

Pajean 253 Pcs Student Behavior Pocket Chart for Classroom Behavior Management Resources Track Reward Bulletin Board Customizable Class Jobs for Home Preschool Daycare Back to School Teacher Supplies

  • ENGAGING, COLORFUL DESIGN: BRIGHT VISUALS TO BOOST STUDENT BEHAVIOR UNDERSTANDING.
  • VERSATILE USE: PERFECT FOR CLASSROOM JOBS, REWARDS, AND BEHAVIOR TRACKING.
  • DURABLE & CONVENIENT: LAMINATED CARDS AND STURDY HOOKS FOR EASY SETUP.
BUY & SAVE
$24.99 $28.99
Save 14%
Pajean 253 Pcs Student Behavior Pocket Chart for Classroom Behavior Management Resources Track Reward Bulletin Board Customizable Class Jobs for Home Preschool Daycare Back to School Teacher Supplies
6 CRAFTYCOO Magnetic Checklist Chore Board with Chore Sticker Book, Chores Chart for Kids, Set of 2 Magnetic Customizable Chore Charts with Insert Paper and 212 Stickers, Chore Chart for Multiple Kids

CRAFTYCOO Magnetic Checklist Chore Board with Chore Sticker Book, Chores Chart for Kids, Set of 2 Magnetic Customizable Chore Charts with Insert Paper and 212 Stickers, Chore Chart for Multiple Kids

  • INTERACTIVE CHART WITH SLIDING BUTTONS MAKES CHORES FUN FOR KIDS!
  • COMES WITH 212 STICKERS TO BOOST MOTIVATION AND ENGAGEMENT.
  • VERSATILE DESIGN SUITS BOTH KIDS AND ADULTS FOR ANY TASK MANAGEMENT.
BUY & SAVE
$13.99
CRAFTYCOO Magnetic Checklist Chore Board with Chore Sticker Book, Chores Chart for Kids, Set of 2 Magnetic Customizable Chore Charts with Insert Paper and 212 Stickers, Chore Chart for Multiple Kids
+
ONE MORE?

To add axis titles to Chart.js charts, you can use the scales option in the configuration object for each respective axis. Here's how you can do it for both the x-axis (horizontal) and y-axis (vertical):

  1. For the x-axis title: Within the options object of your Chart.js chart configuration, add a scales object if it doesn't already exist. Inside the scales object, create a xAxes array if it doesn't already exist. Within the xAxes array, create an object to configure the x-axis properties. Inside the x-axis object, add a scaleLabel object and set its display property to true. Within the scaleLabel object, you can set the axis title by defining the labelString property as the desired title text.
  2. For the y-axis title: Similarly, within the options object of your chart configuration, add a scales object if needed. Inside the scales object, create a yAxes array if it doesn't exist yet. Within the yAxes array, create an object to configure the y-axis properties. Inside the y-axis object, add a scaleLabel object and set its display property to true. Within the scaleLabel object, set the labelString property with the desired title text.

Remember to adjust your configuration based on the specific chart type you are using.

What is the default visibility of axis titles in Chart.js?

The default visibility of axis titles in Chart.js is true, which means that axis titles are displayed by default.

How to change the font family of axis titles in Chart.js?

To change the font family of axis titles in Chart.js, you can use the title object in the scales property of the chart options. Here's an example:

var chartOptions = { scales: { x: { title: { display: true, text: 'X-axis Title', font: { family: 'Arial', size: 16, weight: 'bold' } } }, y: { title: { display: true, text: 'Y-axis Title', font: { family: 'Arial', size: 16, weight: 'bold' } } } } };

var chart = new Chart(ctx, { type: 'bar', data: data, options: chartOptions });

In the above example, font.family sets the font family to Arial for both x-axis and y-axis titles. Adjust the size and weight properties as desired.

There is no specific recommended font size for axis titles in Chart.js. The best font size for axis titles depends on the specific chart's size and the amount of text you need to display.

In general, it is recommended to use a font size that is large enough to be easily readable but small enough to fit within the available space. You can start with a font size of around 12-14 pixels and adjust it as needed based on the chart's size and the length of the axis titles. Additionally, you can also consider using a slightly larger font size for larger charts and a slightly smaller font size for smaller charts to maintain readability.

How to display multiline axis titles in Chart.js?

Currently, Chart.js does not support multiline axis titles out-of-the-box. However, you can achieve multiline axis titles by manually adjusting the chart layout using the layout option.

Here's an example of how you can do it:

  1. First, set up your chart as usual:

var ctx = document.getElementById('myChart').getContext('2d'); var myChart = new Chart(ctx, { type: 'bar', data: {...}, options: {...} });

  1. Then, modify the chart layout options to create multiline axis titles:

var originalScaleDraw = Chart.scaleService.prototype.draw;

Chart.scaleService.prototype.draw = function() { originalScaleDraw.apply(this, arguments);

var ctx = this.chart.ctx;
var fontSize = this.options.ticks.fontSize;
var fontStyle = this.options.ticks.fontStyle;
var fontFamily = this.options.ticks.fontFamily;
var titleFont = Chart.helpers.fontString(fontSize, fontStyle, fontFamily);

ctx.save();
ctx.font = titleFont;
ctx.textBaseline = 'middle';

var yAxis = this.chart.scales\['y-axis-0'\];
var xAxis = this.chart.scales\['x-axis-0'\];

// Display multiline y-axis title
ctx.translate(yAxis.left, yAxis.top + (yAxis.bottom - yAxis.top) / 2);
ctx.rotate(-0.5 \* Math.PI);
ctx.textAlign = 'center';
ctx.fillText('Your multi-line y-axis title', 0, 0);

// Display multiline x-axis title
ctx.translate((xAxis.right - xAxis.left) / 2, xAxis.bottom + xAxis.options.offset);
ctx.textAlign = 'center';
ctx.fillText('Your multi-line x-axis title', 0, 0);

ctx.restore();

};

In the example above, the draw function of the Chart.scaleService prototype is overridden to manually draw the multiline axis titles. Inside the overridden function, the current chart context is obtained, and the necessary font and alignment settings are applied.

The multiline titles are then drawn manually using the fillText method of the canvas context. In this example, the y-axis title is rotated by -0.5 * π (90 degrees counter-clockwise) to display it vertically. The x-axis title is displayed normally.

Make sure to replace 'Your multi-line y-axis title' and 'Your multi-line x-axis title' with your desired multiline axis titles.

With these modifications, the axis titles in your Chart.js chart should be displayed as multiline.

Note: This solution works for the latest version of Chart.js (currently 3.x). If you are using an older version of Chart.js, some adjustments to the code might be necessary.

How to add a title to the Y-axis in Chart.js?

To add a title to the Y-axis in Chart.js, you can use the yAxes configuration option. Here's an example:

var ctx = document.getElementById('myChart').getContext('2d'); var myChart = 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: [ '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: [{ scaleLabel: { display: true, labelString: 'Number of Votes' } }] } } });

In the above example, the options object specifies the scales property, which contains the yAxes array. Inside the yAxes array, you can use the scaleLabel property to add a title to the Y-axis. The display property is set to true to display the title, and the labelString property specifies the actual title text.

How to add a border to axis titles in Chart.js?

In Chart.js, you can add a border to axis titles by using the title option and creating a custom CSS class for the titles that includes a border style.

Here's an example of how you can achieve this:

  1. First, define your chart options including the title configuration:

var options = { title: { display: true, text: 'My Chart Title' }, ... };

  1. Next, create a custom CSS class for the axis titles. In this example, we'll use the class name axis-title:

.axis-title { border: 1px solid black; padding: 5px; background-color: white; }

  1. Finally, apply the custom CSS class to the axis titles using the callback function for the title option. This function allows you to modify the title element directly:

var options = { title: { display: true, text: 'My Chart Title', callback: function(value, index, values) { return "" + value + ""; } }, ... };

Now, the axis titles in your Chart.js chart will have a border style applied to them. You can customize the border style by modifying the CSS class .axis-title.