Skip to main content
MyWebForum

Back to all posts

How to Add A Legend to A Chart.js Chart?

Published on
3 min read
How to Add A Legend to A Chart.js Chart? image

Best Chart.js Accessories to Buy in September 2026

1 Custom Instagram NFC Keychain 3D Printed Tap to Share

Custom Instagram NFC Keychain 3D Printed Tap to Share

  • INSTANTLY SHARE YOUR INSTAGRAM WITH A SIMPLE TAP-NO APP NEEDED!
  • CUSTOM 3D PRINTED DESIGN: STYLISH, COMPACT, AND PERSONALIZED FOR YOU.
  • PERFECT GIFT FOR CREATORS AND SMALL BUSINESSES TO BOOST NETWORKING!
BUY & SAVE
$4.50
2 Custom Instagram NFC Keychain 3D Printed Tap to Share

Custom Instagram NFC Keychain 3D Printed Tap to Share

  • EFFORTLESSLY SHARE YOUR INSTAGRAM WITH A SIMPLE NFC TAP!

  • CUSTOM 3D PRINTED KEYCHAIN-PERFECT FOR CREATORS AND BUSINESSES.

  • COMPACT DESIGN MAKES IT A STYLISH ACCESSORY FOR SOCIAL NETWORKING!

BUY & SAVE
$7.50
3 3 Pcs Marine Navigation Kit, Nautical Chart Plotting Tool Set with Single Hand Divider, Navigation Ruler and Protractor, Drafting Supplies for Boating, Sailing, Seafaring

3 Pcs Marine Navigation Kit, Nautical Chart Plotting Tool Set with Single Hand Divider, Navigation Ruler and Protractor, Drafting Supplies for Boating, Sailing, Seafaring

  • COMPLETE KIT ENSURES SAFE AND EASY NAVIGATION FOR ALL BOATERS.
  • CLEAR SCALES AND HIGH-TRANSPARENCY RULER ENHANCE MEASUREMENT ACCURACY.
  • STABLE CHART PLOTTING TOOLS STREAMLINE YOUR NAVIGATION TASKS EFFICIENTLY.
BUY & SAVE
$25.98 $29.98
Save 13%
3 Pcs Marine Navigation Kit, Nautical Chart Plotting Tool Set with Single Hand Divider, Navigation Ruler and Protractor, Drafting Supplies for Boating, Sailing, Seafaring
4 Meowoo Ring Sizer Measuring Tool with Magnifier, for Ring Measurer and Ring Sizer Clear and Intuitive Reading. Plastic Ring Sizer with Lens, 1-17

Meowoo Ring Sizer Measuring Tool with Magnifier, for Ring Measurer and Ring Sizer Clear and Intuitive Reading. Plastic Ring Sizer with Lens, 1-17

  • CLEAR MEASUREMENT: MAGNIFIER FOR EASY, ACCURATE FINGER SIZING.
  • DURABLE DESIGN: HIGH-QUALITY, REUSABLE RING SIZER FOR LONGEVITY.
  • CONVENIENT SIZES: US SIZES 1-17; PORTABLE FOR ON-THE-GO USAGE!
BUY & SAVE
$3.98
Meowoo Ring Sizer Measuring Tool with Magnifier, for Ring Measurer and Ring Sizer Clear and Intuitive Reading. Plastic Ring Sizer with Lens, 1-17
5 Morse Plastic Pocket Chart (3-Pack) – Machinist Reference for Decimal Equivalents, Recommended Drill Sizes for Taps, and Useful Formulas

Morse Plastic Pocket Chart (3-Pack) – Machinist Reference for Decimal Equivalents, Recommended Drill Sizes for Taps, and Useful Formulas

  • DURABLE PLASTIC CHARTS: POCKET, TOOLBOX, AND DESK-FRIENDLY!
  • INSTANT REFERENCE: NO MORE SEARCHING THROUGH HANDBOOKS!
  • PACK OF 3: ALWAYS HAVE ONE HANDY WHEREVER YOU GO!
BUY & SAVE
$17.99
Morse Plastic Pocket Chart (3-Pack) – Machinist Reference for Decimal Equivalents, Recommended Drill Sizes for Taps, and Useful Formulas
6 Original E-Z Grader - 2017 E-Z Grader, Ombre

Original E-Z Grader - 2017 E-Z Grader, Ombre

  • EFFORTLESS GRADING: SAVE TIME ON HOMEWORK AND TEST ASSESSMENTS!
  • STURDY DESIGN: DURABLE RECTANGLE SHAPE FOR LASTING USE.
  • PERFECT FOR AGES 5+: IDEAL FOR EDUCATORS AND YOUNG LEARNERS!
BUY & SAVE
$14.49
Original E-Z Grader - 2017 E-Z Grader, Ombre
7 Rose Book of Bible Charts, Maps and Time Lines

Rose Book of Bible Charts, Maps and Time Lines

BUY & SAVE
$28.00 $34.99
Save 20%
Rose Book of Bible Charts, Maps and Time Lines
8 Sharpie Flip Chart Markers, Bullet Tip, Assorted Colors, Low-Odor, Squeak-Free, 8 Count - Office Presentation, Back to School, Teacher Supplies

Sharpie Flip Chart Markers, Bullet Tip, Assorted Colors, Low-Odor, Squeak-Free, 8 Count - Office Presentation, Back to School, Teacher Supplies

  • HIGHLY VISIBLE COLORS FOR PRESENTATIONS THAT STAND OUT FROM AFAR.
  • NO-BLEED INK ENSURES CLEAN, PROFESSIONAL FLIP CHART USE EVERY TIME.
  • LOW-ODOR, SQUEAK-FREE DESIGN FOR A COMFORTABLE AND FOCUSED EXPERIENCE.
BUY & SAVE
$8.03
Sharpie Flip Chart Markers, Bullet Tip, Assorted Colors, Low-Odor, Squeak-Free, 8 Count - Office Presentation, Back to School, Teacher Supplies
9 Good Charts Workbook: Tips, Tools, and Exercises for Making Better Data Visualizations

Good Charts Workbook: Tips, Tools, and Exercises for Making Better Data Visualizations

BUY & SAVE
$20.85 $35.00
Save 40%
Good Charts Workbook: Tips, Tools, and Exercises for Making Better Data Visualizations
+
ONE MORE?

To add a legend to a Chart.js chart, you need to specify the legend configuration within the options object when creating the chart. The legend configuration allows you to customize the position, alignment, labels, and styling of the legend within the chart.

To add a legend to a Chart.js chart, you can set the display property of the legend configuration to true. By default, the legend will be displayed at the top of the chart, but you can customize the position using the position property. You can also customize the labels in the legend using the labels property, such as changing the font color, size, or style.

Overall, adding a legend to a Chart.js chart is a simple process that allows you to provide context and additional information for the data being displayed in the chart.

What is the default style of a legend in a Chart.js chart?

The default style of a legend in a Chart.js chart includes a square colored marker next to the label, and the text of the label styled according to the font options specified in the chart configuration. The legend is typically positioned at the bottom of the chart by default.

How to style the legend text in a Chart.js chart?

To style the legend text in a Chart.js chart, you can use the following options in the legend configuration:

  1. fontFamily: This option allows you to specify the font family for the legend text. For example, you can set it to "Arial" or "Helvetica".
  2. fontSize: This option allows you to specify the font size for the legend text. You can set it to a specific size in pixels, such as 12px or 16px.
  3. fontColor: This option allows you to specify the color of the legend text. You can set it to a specific color using a hexadecimal code, RGB value, or color name.

Here is an example of how to style the legend text in a Chart.js chart:

var chart = new Chart(ctx, { type: 'bar', data: data, options: { legend: { labels: { fontFamily: 'Arial', fontSize: 14, fontColor: 'black' } } } });

In this example, the legend text in the chart will be styled with Arial font family, 14px font size, and black color. You can customize these options to fit the design of your chart.

How to format the legend items in a Chart.js chart?

In Chart.js, you can format the legend items by using the legend.labels object in the options when creating the chart. Here's an example of how you can customize the legend items:

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: [ 'red', 'blue', 'yellow', 'green', 'purple', 'orange' ] }] }, options: { legend: { labels: { fontColor: 'black', fontSize: 14, fontStyle: 'bold' } } } });

In this example, we have set the fontColor to black, fontSize to 14, and fontStyle to bold for the legend labels. You can customize other properties as well such as padding, boxWidth, usePointStyle, etc.

You can refer to the Chart.js documentation for more options and examples: https://www.chartjs.org/docs/latest/configuration/legend.html