Quantcast
Channel: How can I hide dataset labels in Chart.js v2? - Stack Overflow
Viewing all articles
Browse latest Browse all 22

Answer by Ludolfyn for Chart.js v2 hide dataset labels

$
0
0

For those who want to remove the actual axis labels and not just the legend in 2021 (Chart.js v.3.5.1). Note: this also removes the axes.

const chartWrap = document.querySelector('.chart-wrap')const canvas = document.createElement('canvas')chartWrap.appendChild(canvas)const ctx = canvas.getContext('2d')const myChart = new Chart(ctx, {    type: 'line',    data: {        labels: ['Your', 'axis', 'labels'],        datasets: [            {                label: 'Your legend label',                data: [1, 3, 2],                backgroundColor: '#54ACEF'            }        ]    },    options: {        maintainAspectRatio: false,        plugins: {            legend: false // Hide legend        },        scales: {            y: {                display: false // Hide Y axis labels            },            x: {                display: false // Hide X axis labels            }        }       }})
<div class="chart-wrap" style="width: 200px; height: 100px;"></div><script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.5.1/chart.min.js" integrity="sha512-Wt1bJGtlnMtGP0dqNFH1xlkLBNpEodaiQ8ZN5JLA5wpc1sUlk/O5uuOMNgvzddzkpvZ9GLyYNa8w2s7rqiTk5Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

Viewing all articles
Browse latest Browse all 22

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>