Skip to content

Instantly share code, notes, and snippets.

@kytiken
Created October 8, 2016 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kytiken/8edf90a8c6355cbdde2555ef65133419 to your computer and use it in GitHub Desktop.
Save kytiken/8edf90a8c6355cbdde2555ef65133419 to your computer and use it in GitHub Desktop.
chart.jsのグラフで軸のラベルを飛び飛びに表示する方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.bundle.min.js"></script>
</head>
<body>
<div style="height: 500px; width: 500px;">
<canvas id="myChart" width="400" height="400"></canvas>
</div>
<script>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: '# of Votes',
data: [{
x: 0,
y: 0
}, {
x: 25,
y: 50
}, {
x: 50,
y: 25
}],
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255,99,132,1)',
borderWidth: 1
}]
},
options: {
scales: {
xAxes: [{
type: 'linear',
position: 'bottom',
ticks: {
callback: function(value) {return ((value % 10) == 0)? value : ''},
min: 0,
max: 50,
stepSize: 1
}
}],
yAxes: [{
ticks: {
callback: function(value) {return ((value % 10) == 0)? value : ''},
min: 0,
max: 50,
stepSize: 1
}
}]
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment