본문 바로가기
프로그래밍/Chart JS

[Chart.js] y축 데이터 범위 설정

by 밍구몬 2019. 8. 21.

0 부터 시작

		options: {
			responsive: false,
			scales: {
				yAxes: [{
					ticks: {
						beginAtZero: true,
						fontSize : 14,
					}
				}]
			}
		}

범위 지정

		options: {
			responsive: false,
			scales: {
				yAxes: [{
					ticks: {
						min: -10;
						max: 25;
						fontSize : 14,
					}
				}]
			}
		}

min에서 +n씩 증가하게 보이기(stepSize)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>chart.js</title>
<head>
	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
</head>
<body>
	<canvas id="myChart" style="height:30vh; width:50vw"></canvas>

	<script>
	var ctx = document.getElementById('myChart');
	var myChart = new Chart(ctx, {
	    type: 'line',
	    data: {
			labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
			datasets: [{
				label: '# of Votes',
				data: [12, 19, 3, 5, 2, 3],
				backgroundColor: [
						'rgba(0, 0, 0, 0)'
				],
				borderColor: [
						'rgba(255, 99, 132, 1)',
						'rgba(54, 162, 235, 1)',
						'rgba(255, 206, 86, 1)',
						'rgba(75, 192, 192, 1)',
						'rgba(153, 102, 255, 1)',
						'rgba(255, 159, 64, 1)'
				],
				borderWidth: 2
			}]
		},
		options: {
			responsive: false,
			scales: {
				yAxes: [{
					ticks: {
						min: -10,
						stepSize : 6,
						fontSize : 14,
					}
				}]
			}
		}
	});
	</script>
</body>