How to draw a bar chart step by step using Chart JS


Hi friends, in this tutorial, you will learn how to draw a bar chart step by step using Chart JS. Actually drawing a bar chart is very easy, you can find many tutorials on Google either using the Google Chart library or the Chart JS library but a question arises when you want to display bar values on top of each bar.

Also, read, Populate dynamic column chart in PHP using Google chart API

In such a case, you can not get the simple method. You will get tutorials but those are a bit complex in order to display the bar values in a simple way, follow the below steps.

Steps to draw a bar chart using Chart js

Step 1:- Create an HTML file (barchart.html) in the root directory of your local server.

Step 2:- Go to Google and search for Chart js plugins data labels or visit here directly and copy the CDN links as given below and paste them into the HTML file you created in Step 1.

https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0    // exact version
https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2        // latest 2.x.x

Step 3:- Now, you need to add the below javascript tags in the HTML file before the body tag ends.

<script src="https://cdn.jsdelivr.net/npm/chart.js@3.0.0/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script>

Step 3:- Now, you have to register the chart data labels manually. Remember to put the below line inside the script tag of your HTML file as shown below.

// Register the plugin to all charts:
Chart.register(ChartDataLabels);

Step 4:- Now, include the data labels under plugins inside the chart options while drawing the chart as shown below.

plugins: {
                  // Change options for ALL labels of THIS CHART
                  datalabels: {
                    color: 'black',
                    font: {
                      weight: 'bold', // You can customize the font style
                    },
                    align:'top',
                    anchor: 'end',
                    display: true, // Display data labels on the bars

                  }
 },

Step 5:- Now, I will draw a bar chart using chart js which displays the rate for each fruit as given in the below HTML file.

barchart.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Fruit Prices Bar Chart</title>
    <!-- <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js@3.0.0/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
</head>
<body>
    <h3>Bar Chart Using Chart JS</h3>
    <div style="width: 600px; height: 400px;">
        <canvas id="fruitPricesChart"></canvas>
    </div>

    <script>
        // Fruit data
        // Register the plugin to all charts:
        Chart.register(ChartDataLabels);
        const fruits = ['Mango', 'Banana', 'Apple', 'Grape', 'Orange'];
        const prices = [30, 50, 80, 90, 100];

        // Create the bar chart
        const ctx = document.getElementById('fruitPricesChart').getContext('2d');
        const chart = new Chart(ctx, {
            type: 'bar',
            data: {
                labels: fruits,
                datasets: [{
                    label: 'Fruit Prices (Rs)',
                    data: prices,
                    backgroundColor: ['rgba(255, 99, 132, 0.6)', 'rgba(255, 159, 64, 0.6)', 'rgba(75, 192, 192, 0.6)'],
                    borderColor: ['rgba(255, 99, 132, 1)', 'rgba(255, 159, 64, 1)', 'rgba(75, 192, 192, 1)'],
                    borderWidth: 1
                }]
            },
            options: {
                plugins: {
                  // Change options for ALL labels of THIS CHART
                  datalabels: {
                    color: 'black',
                    font: {
                      weight: 'bold', // You can customize the font style
                    },
                    align:'top',
                    anchor: 'end',
                    display: true, // Display data labels on the bars

                  }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        ticks: {
                            stepSize: 10 // Adjust the step size of the y-axis ticks as needed
                        }
                    }
                }
            }
        });
    </script>
</body>
</html>

Step 6:- Now open the browser type https://localhost/barchart.html and press ENTER and you will see the output which shows the bar values on top of each bar as shown in the below screenshots.

draw a bar chart step by step using Chart JS

Conclusion:- I hope this tutorial will help you to understand the concept and draw a bar chart in a simple way.


1 thought on “How to draw a bar chart step by step using Chart JS”

Leave a Comment

KUPU178

KUPU178

RATU311

THOR311 TOTO4D

KUPU178

Live Casino Roullate

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

THOR311

THOR311

THOR311

RATU311

CERI188

DAFTAR KUPU178

LINK DAFTAR CERI188

CERI188

sabung ayam online

APK KUPU178

KUPU178

CERI188

CERI188

RATU311

KUPU178

THOR311 DOMINO QQ

judi bola online

Mix Parlay

CERI188

CERI188

CERI188

KUPU178

RATU311

live casino online

RATU311

Mix Parlay

Sabung Ayam Online

Slot PG Soft

CERI188

RATU311

RATU311

RATU311

RATU311

CERI188

THOR311

CERI188

THOR311

RATU311

THOR311

Game Thor311

THOR311

HOKI311

live casino

sv388

HOKI311

HOKI311

slot mahjong

Thor311 Alternatif

RATU311

HOKI311

HOKI311

HOKI311

HOKI311

CERI188

THOR311 RESMI

THOR311 AKSES

THOR311

THOR311 RTP

RATU311

RATU311

THOR311

parlay

HOKI311

RATU311

THOR311

Ceri188

Thor311 Game Online

Thor311 Aplikasi

LINK CERI188

RATU311 NONTON BOLA

RATU311

CERI188 Link RTP LIVE

THOR311

Thor311 Live Casino

CERI188

akses VIP THOR311

THOR311

link daftar THOR311

THOR311

situs thor311

THOR311 LOGIN

THOR311

RATU311

HOKI311 Link SABUNG AYAM RESMI

HOKI311 Link QRIS EWALLET

RATU311

LINK CERI188

parlay

HOKI311 Link RTP Gacor

THOR311

RATU311

HOKI311 Link Apk Resmi

RATU311

RATU311

CERI188

CERI188 Situs Spaceman Terbaik 2026

KUPU178 Link Daftar

CERI188

CERI188

CERI188

CERI188

CERI188

HOKI311

THOR311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

CERI188 Live Casino

HOKI311 Lapak Arena Slot

RATU311 judi bola

CERI188 Live Casino

HOKI311 Link Spaceman Online

HOKI311 Link Daftar Resmi

CERI188 Toto SGP Online

KUPU178

KUPU178

KUPU178

KUPU178

HOKI311 TEMBAK IKAN ONLINE

RATU311

CERI188 PANDUAN MAXWIN SLOT ONLINE

RATU311

RATU311

KUPU178

HOKI311 Link Login Alternatif

HOKI311 Live Casino Online

HOKI311 Situs Slot Gacor

THOR311

THOR311

situs judi bola

Ceri188 Game Online

CERI188

link login CERI188

link login CERI188

CERI188

link login CERI188

link login CERI188

link daftar CERI188

THOR311

HOKI311

HOKI311

CERI188

CERI188

CERI188

parlay

THOR311

RATU311

RATU311

HOKI311

HOKI311

parlay

HOKI311

RATU311

THOR311

KUPU178

HOKI311

KUPU178

KUPU178

KUPU178

HOKI311

parlay

slot gacor

kupu178 link alternatif

kupu178 slot

kupu178 daftar

kupu178 login

link daftar kupu178

judi bola

HOKI311

RATU311

link alternatif RATU311

Link daftar RATU311

link login RATU311

RATU311

RATU311

RATU311

RATU311

KUPU178

KUPU178

THOR311

KUPU178

KUPU178

KUPU178

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

RATU311

THOR311

RATU311

KUPU178

KUPU178

HOKI311

THOR311

KUPU178

THOR311

THOR311

slot thailand

judi bola

THOR311

THOR311

KUPU178

THOR311

situs bola

THOR311

slot gacor

slot gacor

yakuza303

slot gacor

unobet77

slot gacor

slot gacor

RATU311

parlay

parlay

slot gacor

mix parlay

judi bola

judi bola

mix parlay

parlay

judi bola

sv388

judi bola

judi bola

judi bola

parlay

THOR311