본문 바로가기
Java . Spring . Web . SQL

2020/09/10 : jqPlot : 파이(pie) 차트 (원형 그래프)

by heidish 2020. 9. 10.
반응형

파이차트는 원형 그래프이기 때문에 x, y축이라는 개념이 없다.

단, 주어진 값을 360도로 나눠서 범위를 정해준다.

 

파이차트의 라이브러리는 바차트와 다른 것 주의하기

 

더보기
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>jQuery</title>
	
	<!-- 제이쿼리 모바일, 제이쿼리 라이브러리 파일 -->
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"/>
	<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
	<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
	
	<!-- jqPlot 기본 라이브러리 파일 -->
	<link rel="stylesheet" href="jqplot/jquery.jqplot.min.css"/>
	<script src="jqplot/jquery.jqplot.min.js"></script>
	
	<!-- jqPlot 파이 차트 플러그인 파일 -->
	<script src="jqplot/plugins/jqplot.pieRenderer.min.js"></script>
	
	
	<!-- 제이쿼리 -->
	<script>
		$(document).ready(function() {
			var plot1 = $.jqplot('chartdiv', [[['서울', 18], ['경기', 14], ['강원', 3], ['기타', 7]]],
				{
					title: '원형 그래프 예제',
					
					gridPadding: { top:25, bottom:38, left:0, right:0 },
					
					seriesDefaults: {
						renderer: $.jqplot.PieRenderer,
						rendererOptions: { padding: 8, showDataLabels: true }
					},
					
					legend: {
						show: true,
						placement: 'outside',
						
						rendererOptions: {
							numberRows: 1
						},
						
						location: 's',
						
						marginTop: '15px'
					}
				});
		});
	</script>
</head>
<body>
	<div data-role="page">				<!-- 1. 페이지 선언  -->
		<div data-role="header">		<!-- 2. 페이지의 상단 부분 선언  -->
			<h1>header 영역</h1>
		</div>
		<div data-role="content">		<!-- 3. 페이지의 컨텐츠 부분 선언  -->
			<div id="chartdiv" style="height: 400px; width: 300px;">
				<!-- 차트 표시 영역 -->
			</div>
		</div>
		<div data-role="footer" data-position="fixed">	<!-- 4. 페이지의 하단부 선언 -->
			<h4>footer 영역</h4>
		</div>
	</div>
</body>
</html>

 

27 :: gridPadding 이란, 원형 그래프가 테두리 받스에서 얼마나 떨어졌는지를 나타낸다.

32 :: showDataLabels: true 로 되어있기 때문에 그래프 위에 숫자% 가 뜨는것임.

      주어진 값을 360으로 나눠서 퍼센트로 만든것!

39 :: rendererOptions 의 numberRows를 1 로 했음...

 

 

실행 결과

반응형

댓글