반응형
250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Kafka
- java bigdecimal
- Airflow
- kubeflow
- Spring Error
- JavaScript
- bootstrap
- node
- codebuild
- Spring
- codepipeline
- 도커
- codedeploy
- AWS CI/CD 구축하기
- or some instances in your deployment group are experiencing problems.
- Flux
- codedeploy error
- aws cicd
- chart.js
- IntelliJ
- Python
- PostgreSQL
- docker
- aws
- SQL
- VPN
- Jenkins
- COALESCE
- chartjs
- redis
Archives
- Today
- Total
Small Asteroid Blog
[chart.js] tooltip 선택 시 value, percentage 둘다 표시 본문
728x90
chartjs 를 이용해서 차트를 표현하는데 아래 이미지와 같이
tooltip에 value와 percentage를 둘 다 표시하고자 한다.

options : {
tooltips : {
callbacks : {
label : function(tooltipItem, data){
var dataset = data.datasets[tooltipItem.datasetIndex];
var total = dataset.data.reduce(function(previousValue, currentValue, currentIndex, array){
return previousValue + currentValue;
});
var currentValue = dataset.data[tooltipItem.index];
var percentage = Math.floor(((currentValue/total) * 100)+0.5);
return data['labels'][tooltipItem['index']] + " : " + currentValue + " ("+ percentage+"%)" ;
},
}
},//tooltips
}
728x90
반응형
'프론트엔드 > Javascript' 카테고리의 다른 글
ajax xml 전체내용 출력 (0) | 2021.04.07 |
---|---|
dataTable 한국어 함수 (0) | 2021.02.15 |
window.onload 와 $(document).ready 의 차이 (0) | 2021.02.15 |
script5007 정의되지 않음 또는 null 참조인 속성을 가져올 수 없습니다. (0) | 2020.07.07 |
[chart.js] 레이블 글자가 길 때 (띄어쓰기, 글자 길이) (0) | 2020.07.01 |