Skip to content

Instantly share code, notes, and snippets.

@miyohide
Created May 13, 2024 12:11
Show Gist options
  • Save miyohide/92893b2a3ba2067e5b6e1bd2e542a179 to your computer and use it in GitHub Desktop.
Save miyohide/92893b2a3ba2067e5b6e1bd2e542a179 to your computer and use it in GitHub Desktop.
Chart.jsを使ってランニングのペースをグラフ化する
<div>
<canvas id="myChart"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
const ctx = document.getElementById('myChart');
new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar'],
datasets: [{
label: 'pace per kilometer',
data: [264, 261, 251],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true,
reverse: true, // 大きいものから小さいものに
ticks: {
// 秒の値を分:秒の形式にする
callback: function(value, index, values) {
var minutes = Math.floor(value / 60);
var seconds = value % 60;
return minutes + ":" + (seconds < 10 ? "0" : "") + seconds;
}
}
}
}
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment