Created
October 8, 2016 06:08
-
-
Save kytiken/8edf90a8c6355cbdde2555ef65133419 to your computer and use it in GitHub Desktop.
chart.jsのグラフで軸のラベルを飛び飛びに表示する方法
This file contains 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
<!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