Last active
July 3, 2018 09:15
-
-
Save donma/58521e91e15608cc1e3df208055f98c2 to your computer and use it in GitHub Desktop.
Chart.js Pie Tooltips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 關於滑過後的 顯示 | |
tooltips: { | |
callbacks: { | |
label: function (tooltipItem, data) { | |
var dataset = data.datasets[tooltipItem.datasetIndex]; | |
//計算總和 | |
var sum = dataset.data.reduce(function (previousValue, currentValue, currentIndex, array) { | |
return previousValue + currentValue; | |
}); | |
var currentValue = dataset.data[tooltipItem.index]; | |
var percent = Math.round(((currentValue / sum) * 100)); | |
return " " + data.labels[tooltipItem.index] + ":" + currentValue + " (" + percent + " %)"; | |
} | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment