Skip to main content
freelanceshack.com

Back to all posts

How to Create A Horizontal Bar Chart In Chart.js?

Published on
4 min read
How to Create A Horizontal Bar Chart In Chart.js? image

Best Chart Design Tools to Buy in November 2025

1 Dunzoom 3 Pcs Marine Navigation Kit, Basic Navigation Set Include 18" Marine Parallel Ruler with Clear Scales, 8" Diameter Nautical Plotter Protractor, 6" Fixed Point Divider for Boat Accessories

Dunzoom 3 Pcs Marine Navigation Kit, Basic Navigation Set Include 18" Marine Parallel Ruler with Clear Scales, 8" Diameter Nautical Plotter Protractor, 6" Fixed Point Divider for Boat Accessories

  • ALL-IN-ONE NAVIGATION KIT: ESSENTIAL TOOLS FOR EVERY MARINE ADVENTURE.
  • DURABLE & ACCURATE: CRAFTED FOR RELIABILITY IN HARSH MARINE CONDITIONS.
  • USER-FRIENDLY DESIGN: EASY TO USE, ENHANCING YOUR SAILING EXPERIENCE.
BUY & SAVE
$32.99
Dunzoom 3 Pcs Marine Navigation Kit, Basic Navigation Set Include 18" Marine Parallel Ruler with Clear Scales, 8" Diameter Nautical Plotter Protractor, 6" Fixed Point Divider for Boat Accessories
2 Weems & Plath #176 Marine Navigation Ultralight Divider

Weems & Plath #176 Marine Navigation Ultralight Divider

  • DURABLE MARINE ALLOY COATING RESISTS CORROSION FOR LASTING USE.
  • EASY-TO-USE CENTER GEAR MECHANISM WITH SPARE ACCESSORIES INCLUDED.
  • PROUDLY MADE IN GERMANY WITH A LIFETIME WARRANTY FOR PEACE OF MIND.
BUY & SAVE
$29.00
Weems & Plath #176 Marine Navigation Ultralight Divider
3 Saysurey Parallel Ruler Marine Navigation Tool with Clear Scales Parallel Ruler with Brushed Aluminum Arms Nautical Charts Navigation Tools for Boat Ship Drawing(12 Inch)

Saysurey Parallel Ruler Marine Navigation Tool with Clear Scales Parallel Ruler with Brushed Aluminum Arms Nautical Charts Navigation Tools for Boat Ship Drawing(12 Inch)

  • PLOT ACCURATE BEARINGS EFFORTLESSLY WITH OUR DURABLE 12-INCH RULER!
  • ENJOY UNMATCHED DURABILITY WITH QUALITY ACRYLIC AND ALUMINUM DESIGN.
  • EXPERIENCE PRECISION WITH CLEAR SCALES AND 180° PROTRACTOR MARKINGS.
BUY & SAVE
$18.99 $19.99
Save 5%
Saysurey Parallel Ruler Marine Navigation Tool with Clear Scales Parallel Ruler with Brushed Aluminum Arms Nautical Charts Navigation Tools for Boat Ship Drawing(12 Inch)
4 Motipuns 3 Pcs Basic Navigation Set, Include 16 Inch Marine Parallel Ruler with Clear Scales Navigation Divider Marine Nautical Protractor 6 Inch Marine Fixed Points Divider for Boat

Motipuns 3 Pcs Basic Navigation Set, Include 16 Inch Marine Parallel Ruler with Clear Scales Navigation Divider Marine Nautical Protractor 6 Inch Marine Fixed Points Divider for Boat

  • ALL-IN-ONE NAVIGATION KIT: ESSENTIAL TOOLS FOR PRECISION ON THE WATER.
  • DURABLE & CLEAR MEASURING TOOLS: ACRYLIC RULER ENSURES LONG-LASTING ACCURACY.
  • EASY-TO-USE FOR PRACTICE: MASTER NAVIGATION SKILLS ANYTIME, ANYWHERE!
BUY & SAVE
$32.99 $34.99
Save 6%
Motipuns 3 Pcs Basic Navigation Set, Include 16 Inch Marine Parallel Ruler with Clear Scales Navigation Divider Marine Nautical Protractor 6 Inch Marine Fixed Points Divider for Boat
5 Weems & Plath Marine Navigation Primary Navigation Set

Weems & Plath Marine Navigation Primary Navigation Set

  • ULTRALIGHT DESIGN FOR EASY PORTABILITY AND PRECISION NAVIGATION.
  • VERSATILE TOOLS: RULER, COMPASS, AND SLIDE RULE FOR ALL NEEDS.
  • DURABLE STORAGE POUCH KEEPS EVERYTHING ORGANIZED AND PROTECTED.
BUY & SAVE
$92.00
Weems & Plath Marine Navigation Primary Navigation Set
6 WEEMS & PLATH Essentials Navigation Kit

WEEMS & PLATH Essentials Navigation Kit

  • ULTRALIGHT DESIGN ENHANCES PORTABILITY FOR ON-THE-GO NAVIGATION.
  • PRECISION PLOTTING WITH WEEMS PARALLEL PLOTTER FOR ACCURACY.
  • NAUTICAL SLIDE RULE SIMPLIFIES CALCULATIONS FOR SAFE SAILING.
BUY & SAVE
$84.00
WEEMS & PLATH Essentials Navigation Kit
+
ONE MORE?

To create a horizontal bar chart in Chart.js, you first need to include the Chart.js library in your HTML file. Then, you can create a canvas element where the chart will be displayed. Next, you need to initialize a new Chart object and specify the type of chart as 'horizontalBar'.

You also need to provide data for the chart in the form of an array of objects. Each object should have a 'label' and 'data' property, which will be used to label the bars and specify their values, respectively.

Finally, you can customize the appearance of the chart by setting various options such as colors, labels, and tooltips. Once you have configured the chart to your liking, you can render it by calling the 'update' method on the Chart object. This will display the horizontal bar chart on your webpage for viewers to see and interact with.

What is the legend feature in Chart.js bar charts?

The legend feature in Chart.js bar charts is a key that provides information about the datasets represented in the chart. It typically displays a colored box or line next to a label, indicating which dataset each color or line represents. The legend helps viewers understand the data being displayed and allows them to easily distinguish between different datasets in the chart.

How to make a stacked bar chart in Chart.js?

To create a stacked bar chart in Chart.js, you will need to use the 'bar' type chart and set the 'stacked' property to true in the dataset options. Here is an example code snippet to create a stacked bar chart:

<script>
    var ctx = document.getElementById('myChart').getContext('2d');
    var myChart = new Chart(ctx, {
        type: 'bar',
        data: {
            labels: \['January', 'February', 'March', 'April', 'May'\],
            datasets: \[
                {
                    label: 'Dataset 1',
                    data: \[10, 20, 30, 40, 50\],
                    backgroundColor: 'rgba(255, 99, 132, 0.2)',
                    borderColor: 'rgba(255, 99, 132, 1)',
                    borderWidth: 1
                },
                {
                    label: 'Dataset 2',
                    data: \[15, 25, 35, 45, 55\],
                    backgroundColor: 'rgba(54, 162, 235, 0.2)',
                    borderColor: 'rgba(54, 162, 235, 1)',
                    borderWidth: 1
                }
            \]
        },
        options: {
            scales: {
                x: {
                    stacked: true,
                },
                y: {
                    stacked: true
                }
            }
        }
    });
</script>

In this example, we have created a simple stacked bar chart with two datasets. The 'stacked' property is set to true for both the x-axis and y-axis scales to create the stacked effect. You can customize the labels, data, and colors of the datasets according to your requirements.

How to update data in a bar chart using Chart.js?

To update data in a bar chart using Chart.js, you can follow these steps:

  1. Get a reference to the chart instance: First, you need to get a reference to the chart instance using the getElementById method or by storing the chart instance in a variable when creating the chart.

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 } } } });

  1. Update the data: You can update the data in the datasets array of the chart instance and then call the update method on the chart to redraw it with the updated data.

// Update the data myChart.data.datasets[0].data[2] = 10;

// Call the update method myChart.update();

In this example, we are updating the third data point in the dataset to be 10 and then calling the update method on the chart instance to redraw the chart with the updated data.

By following these steps, you can easily update data in a bar chart using Chart.js.

What is the purpose of using datasets in a bar chart with Chart.js?

The purpose of using datasets in a bar chart with Chart.js is to organize and display the data in a clear and visually appealing way. Datasets allow users to input data points and corresponding labels that will be plotted on the chart. By using datasets, users can customize the appearance of each bar, such as color and hover effects, and add data labels to provide more context to the information being presented. Overall, datasets help in presenting data in a structured and understandable manner in a bar chart.