250x250
Notice
Recent Posts
Recent Comments
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

진스

Chart.js 옵션 dataset labels 숨기/ 클릭 tooltip 내용 본문

카테고리 없음

Chart.js 옵션 dataset labels 숨기/ 클릭 tooltip 내용

입방정 2021. 5. 26. 17:08
728x90

라벨 dataset labels 숨기는 방법

var ctx = $('#gold_chart');
var goldChart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: dates,
        datasets: [{
            label: 'I want to remove this Label',
            data: prices,
            pointRadius: 0,
            borderWidth: 1
        }]
    }
});

차트를 만들어내는 js 코드가 있다고 가정하자. 여기서 labels을 숨기는 방법은 아주 간단하다.

...
options: {
    legend: {
        display: false
    },
    tooltips: {
        callbacks: {
           label: function(tooltipItem) {
                  return tooltipItem.yLabel;
           }
        }
    }
}

 

다음과 같이 legend의 display를 false로 설정하면 깔끔하게 label이 숨겨진다.

 

 

 

https://www.chartjs.org/docs/latest/charts/line.html
https://stackoverflow.com/questions/37204298/chart-js-v2-hide-dataset-labels

 

출처

 

 

Chart.js 라벨 dataset labels 숨기는 방법

Chart.js를 사용하던 도중 label을 숨기는 요구사항을 받았다. 이미 h tag 로 차트 타이틀에 대한 정보를 표시하고 있기 때문!

velog.io

 

 

 

클릭하면 나오는tooltip lable내용 변경

...
options: {
    legend: {
        display: false
    },
    tooltips: {
        callbacks: {
           label: function(tooltipItem) {
                  return tooltipItem.yLabel;
           }
        }
    }
}

출처

 

 

Chart.js v2 hide dataset labels

I have the following codes to create a graph using Chart.js v2.1.3: var ctx = $('#gold_chart'); var goldChart = new Chart(ctx, { type: 'line', data: { labels: dates, datase...

stackoverflow.com

 

728x90
Comments