Skip to main content
PHP Blog

Back to all posts

How to Set Y-Axis Label on Chart.js?

Published on
5 min read
How to Set Y-Axis Label on Chart.js? image

Best Chart.js Y-Axis Labeling Tools to Buy in October 2025

1 Rose Book of Bible Charts, Maps, and Time Lines

Rose Book of Bible Charts, Maps, and Time Lines

BUY & SAVE
$22.48 $34.99
Save 36%
Rose Book of Bible Charts, Maps, and Time Lines
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 TOOL: INSTANT CONVERSIONS, SIZES, AND MORE IN ONE CARD.

  • DURABLE & LONG-LASTING: MADE FROM QUALITY MATERIALS FOR MAXIMUM STURDINESS.

  • PORTABLE & VERSATILE: PERFECT FOR INDOOR OR OUTDOOR USE-TAKE IT ANYWHERE!

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 All-in-One Quilter's Reference Tool: Updated

All-in-One Quilter's Reference Tool: Updated

  • COMPREHENSIVE REFERENCE FOR ALL QUILTING TECHNIQUES AND TIPS.
  • UPDATED SOFTCOVER DESIGN FOR EASY PORTABILITY AND DURABILITY.
  • USER-FRIENDLY LAYOUT ENHANCES QUICK ACCESS TO ESSENTIAL INFO.
BUY & SAVE
$15.97 $17.95
Save 11%
All-in-One Quilter's Reference Tool: Updated
4 General Tools 715 Tap and Drill Reference Table

General Tools 715 Tap and Drill Reference Table

  • DOUBLE-SIDED DESIGN: TAP DRILL CHART & DECIMAL CONVERSIONS.
  • 6-INCH RULER: PRECISE MEASUREMENTS GRADUATED IN 64THS.
  • ESSENTIAL FOR MACHINISTS: BOOSTS EFFICIENCY FOR TOOLMAKERS.
BUY & SAVE
$11.57
General Tools 715 Tap and Drill Reference Table
5 The Living Legacy of Trauma Flip Chart: A Psychoeducational In-Session Tool for Clients and Therapists

The Living Legacy of Trauma Flip Chart: A Psychoeducational In-Session Tool for Clients and Therapists

BUY & SAVE
$29.00 $44.99
Save 36%
The Living Legacy of Trauma Flip Chart: A Psychoeducational In-Session Tool for Clients and Therapists
6 The CBT Flip Chart: An Evidence-Based Psychoeducational Tool for Anxiety, Depression, Stress, Insomnia, PTSD, and More

The CBT Flip Chart: An Evidence-Based Psychoeducational Tool for Anxiety, Depression, Stress, Insomnia, PTSD, and More

BUY & SAVE
$29.31 $42.99
Save 32%
The CBT Flip Chart: An Evidence-Based Psychoeducational Tool for Anxiety, Depression, Stress, Insomnia, PTSD, and More
7 How to Read a Nautical Chart, 2nd Edition (Includes ALL of Chart #1): A Complete Guide to Using and Understanding Electronic and Paper Charts

How to Read a Nautical Chart, 2nd Edition (Includes ALL of Chart #1): A Complete Guide to Using and Understanding Electronic and Paper Charts

BUY & SAVE
$12.48 $26.00
Save 52%
How to Read a Nautical Chart, 2nd Edition (Includes ALL of Chart #1): A Complete Guide to Using and Understanding Electronic and Paper Charts
+
ONE MORE?

To set the y-axis label on a chart using Chart.js, you can use the scales option within the options object of the chart configuration. Within the scales option, you can define the yAxes property which contains an array of objects representing the y-axes on the chart. Within each y-axis object, you can set the scaleLabel property to configure the label for the y-axis. For example:

options: { scales: { yAxes: [{ scaleLabel: { display: true, labelString: 'Y-axis Label' } }] } }

In the above example, the display property is used to set whether the label is displayed or not, and the labelString property is used to specify the actual text of the label. Customize these properties as needed to set your desired y-axis label on the Chart.js chart.

What is the syntax for setting the y-axis label in chart.js?

To set the y-axis label in Chart.js, you can use the yAxes option in the options object of your chart configuration. Here is an example of how you can set the y-axis label:

options: { scales: { yAxes: [{ scaleLabel: { display: true, labelString: 'Y-axis Label' } }] } }

In this example, the scaleLabel object is used within the yAxes array to specify the display settings for the y-axis label. The display property is set to true to display the label, and the labelString property is set to the desired label text (in this case, 'Y-axis Label').

What is the purpose of the y-axis in a chart?

The purpose of the y-axis in a chart is to show and represent the dependent variable or variables in a particular data set. The y-axis usually represents the vertical axis on a graph and is used to measure and display the values of the data points being plotted. It helps to provide a visual representation of the relationship between the variables being analyzed and allows for easy comparisons and interpretation of the data.

How to set a prefix for the y-axis label in chart.js?

To set a prefix for the y-axis label in Chart.js, you can use the callback function in the scales option of the chart configuration. Here is an example code snippet that adds a dollar sign prefix to the y-axis label:

var ctx = document.getElementById('myChart').getContext('2d'); var myChart = new Chart(ctx, { type: 'bar', data: { labels: ['January', 'February', 'March', 'April', 'May'], datasets: [{ label: 'Sales', data: [1000, 1500, 1200, 1800, 2000], }] }, options: { scales: { y: { ticks: { callback: function(value, index, values) { return '$' + value; } } } } } });

In this example, we have added a callback function to the ticks option for the y-axis. This function takes three parameters: value (the tick value), index (the index of the tick value), and values (an array of all the tick values).

Inside the callback function, we are simply concatenating a dollar sign ('$') before the tick value. You can customize the prefix as per your requirement.

Make sure to replace myChart with your actual Chart.js chart instance variable and myChart with the ID of your canvas element where the chart is rendered.

What is the difference between primary and secondary y-axis in chart.js?

In Chart.js, the primary y-axis refers to the default y-axis that is automatically generated for a chart based on the data provided. This y-axis is typically located on the left side of the chart and is shared by all the datasets displayed on the chart.

On the other hand, the secondary y-axis is an additional y-axis that can be added to the chart to display data from specific datasets separately. This y-axis is typically located on the right side of the chart and can have its own scale and range, independent of the primary y-axis.

In summary, the primary y-axis is the default y-axis shared by all datasets on the chart, while the secondary y-axis is an additional y-axis that can be added to display specific data separately.

What is the default position of the y-axis label in chart.js?

The default position of the y-axis label in chart.js is "left".

How to change the font size of the y-axis label in chart.js?

To change the font size of the y-axis label in Chart.js, you can use the "scales" option in the configuration object of the chart. Here's an example of how to do this:

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: { y: { beginAtZero: true, ticks: { fontSize: 16 // Change the font size of the y-axis label here } } } } });

In this example, we set the fontSize property of the ticks object inside the options.scales.y object to 16, which will change the font size of the y-axis label to 16. You can adjust the value of fontSize to your desired font size.