var ctx = document.getElementById("chart").getContext("2d");
// original data array
var data = [1, -2, 3, -4];
// temporary data array \w absolute values
var temp_data = data.map(function(e) {
return Math.abs(e);
});
var myDoughnut = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ["January", "February", "March", "April"],
datasets: [{
data: temp_data,
backgroundColor: ['#ff3d67', '#ff9f40', '#ffcd56', '#4bc0c0'],
}]
},
showDatapoints: true,
options: {
responsive: false,
legend: false,
tooltips: {
displayColors: false,
callbacks: {
label: function(t, d) {
return d.labels[t.index] + ': ' + data[t.index]; // 'data' represents the original data array
}
}
}
}
});
body{margin-top:0;overflow:hidden}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="chart" width="218"></canvas>
謝謝。我不明白爲什麼圖書館不提供回調,但你的解決方案就像一個魅力。 – Korbraan
不客氣。 –