SlideShare a Scribd company logo
Data Designer
D3.js
04: D3.js 척도와 축 (Scale & Axis)
꿈꾸는데이터디자이너 시즌2오늘의 수업
이론 실습
1. D3.js의 축과 척도
2. 막대그래프 속성 이해하기
1. 막대그래프에 축과 척도 적용
꿈꾸는데이터디자이너 시즌2d3.js 척도 (d3.scale)
D3.js척도기능은
요소의위치를크기에비례해자동으로계산해준다
꿈꾸는데이터디자이너 시즌2
척도:입력되는정의역(domain)과출력되는치역(range)을매핑한함수
.domain( )
.range( )
입력되는데이터값의범위
출력되는범위(단위:픽셀)
d3.scale( )
d3.js 척도 (d3.scale)
꿈꾸는데이터디자이너 시즌2
d3.scale.linear( )
d3.scale.ordinal( )
선형척도.숫자,날짜등일련의연속적인값을갖는척도.
서열척도.이름,항목등측정이불가능한값일경우사용하는척도.
d3.js 척도 (d3.scale)
꿈꾸는데이터디자이너 시즌2
01_scale_test_blank.html
d3.scale.linear( )
.domain[시작점, 끝점]
.range[시작점, 끝점]
여기는척도의종류에따라바뀝니다
d3.js 척도 (d3.scale)
척도를설정하기위해서는 척도의종류,입력하는데이터값의범위,출력되는범위가모두필요하다
data
d3.scale
data
꿈꾸는데이터디자이너 시즌2
데이터의최솟값과최댓값을
일일이적어야할까?
d3.js 척도 (d3.scale)
꿈꾸는데이터디자이너 시즌2d3.min & max
d3.min( )
d3.max( )
데이터안의최솟값을반환하는함수
데이터안의최댓값을반환하는함수
데이터값이많아질수록최솟값과최댓값을직접지정하기힘들기때문에사용하는함수
꿈꾸는데이터디자이너 시즌2d3 축과 척도
척도
웹화면에SVG요소추가
(선,라벨,눈금등)
값을계산해반환
축
d3.scale( )
d3.axis( )
꿈꾸는데이터디자이너 시즌2d3.axis( )
d3.svg.axis()
d3.js의축함수를생성함.
꿈꾸는데이터디자이너 시즌2d3.axis( )
축을 생성하는 함수
축을 생성할 때는 어떤 척도를 다뤄야 하는지
알려줘야 함.
축의 위치
가로축 세로축
top left
bottom right
d3.svg.axis()
.scale()
.orient(“__”)
.ticks( )
눈금개수
d3는 대략적으로 필요한 구분자의 개수와 간격 결정
수동으로 눈금 수를 정할 때는 ticks 사용. 단 규칙성에 따라 눈금 수를 결정.
꿈꾸는데이터디자이너 시즌2
실습
꿈꾸는데이터디자이너 시즌2[실습 ] 오늘의 결과물
02_bar_blank.html
꿈꾸는데이터디자이너 시즌2[실습] d3.js scale & axis
Tip svg ‘g’ 개념
g
‘그룹’.다른문서요소를묶어서담는역할.위치를차지하지않고,보이지않는다.
svg.append(“g”)
.call(yAxis);
var yAxis =d3.svg.axis()
.scale(yScale)
.orient(“bottom”);
SVG 안에 g 생성
yAxis 호출
g 안에 축 요소 생성
축함수는SVG관련요소를추가한다.
때문에문서요소가어디에있어야하는지정해줘야한다.
이를위해미리그룹을생성한후축요소를추가한다.
꿈꾸는데이터디자이너 시즌2[실습] d3.js scale & axis
Tip HTML의 요소 영역 개념과 나열 방향
상
HTML의방향은상우하좌!
Border
Content
Padding
Margin
하
좌 우
꿈꾸는데이터디자이너 시즌2
D3.js 그래프 요소 자리
y축
x축
전체 영역
여백
[실습] d3.js scale & axis
이동
꿈꾸는데이터디자이너 시즌2[실습] d3.js scale & axis
top
이동
bottom
left right
translate(" + margin.left + "," + margin.top + ")")
x y
꿈꾸는데이터디자이너 시즌2
x축
y축
[실습] d3.js scale & axis
x축은위치를지정하지않으면상단에생성된다
꿈꾸는데이터디자이너 시즌2
.attr("transform", "translate(0," + height + ")")
x축
y축
[실습] d3.js scale & axis
translate기능을이용해x축을아래로이동한다
꿈꾸는데이터디자이너 시즌2[실습] d3.js scale & axis
.domain(data.map)?
1. 막대그래프는서열척도이기때문에항목명을나열해야한다.
2. 원래형태는항목명을.domain에일일이나열해야한다.
var x = d3.scale.ordinal()
.domain([“중구”, "종로구", “서대문구" (…)])
.rangeBands([0, width], .1);
3.데이터항목이많아질수록일일이입력하는것은한계가있다.
4.(.map)메서드를이용해배열로만들어데이터를삽입한다.
Tip 자바스크립트 ‘배열(Array)’
[“A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”]
자바스크립트의배열은데이터값을하나의목록으로만든것.배열의개별값은원소(element)라고부른다.
http://bost.ocks.org/mike/bar/3/[참고링크]
꿈꾸는데이터디자이너 시즌2
rangeBand rangeBand rangeBand
전체 범위
padding paddingouterPadding outerPadding
나눠진 범위
[실습] d3.js scale & axis
.rangeBand
https://github.com/mbostock/d3/wiki/Ordinal-Scales[참고링크]
막대그래프의항목명을전체범위에맞게자동으로계산해항목을나열함
꿈꾸는데이터디자이너 시즌2[실습] d3.js scale & axis
Tip 숫자 1,000단위 구분 콤마(,) 추가
d3.format
d3내에서숫자형식을다루는메서드
d3.format(“,”)
d3.format(“,.2f”)
d3.format(“,%”)
10000
10,000
10,000.00
10,000%
https://github.com/mbostock/d3/wiki/Formatting[참고링크]
꿈꾸는데이터디자이너 시즌2[실습] d3.js scale & axis
Tip SVG Text요소 정렬하기
text-anchor
SVGText요소의정렬은text-anchor속성을이용한다.
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor[참고링크]
A
A
Astart
middle
end
왼쪽정렬
가운데정렬
오른쪽정렬
Neuro Associates
・ Portfolio : neuroassociates.co.kr/portfolio
・ Address : 서울특별시 마포구 상수동 145-1 6F
・ Site : neuroassociates.co.kr
・ Mail : neuro.associates.consulting@gmail.com or info@neuroassociates.co.kr
・ SNS : www.facebook.com/neuroassociatessns
・ Phone : 02-334-2013

More Related Content

What's hot

[Week13] D3.js_Bar Chart
[Week13] D3.js_Bar Chart[Week13] D3.js_Bar Chart
[Week13] D3.js_Bar Chart
neuroassociates
 
[week12] D3.js_Basic
[week12] D3.js_Basic[week12] D3.js_Basic
[week12] D3.js_Basic
neuroassociates
 
[week16] D3.js (Scale & axis)
[week16] D3.js (Scale & axis)[week16] D3.js (Scale & axis)
[week16] D3.js (Scale & axis)
neuroassociates
 
[Week12] D3.js_Basic2
[Week12] D3.js_Basic2[Week12] D3.js_Basic2
[Week12] D3.js_Basic2
neuroassociates
 
꿈데디 D3.js강의 2주차
꿈데디 D3.js강의 2주차꿈데디 D3.js강의 2주차
꿈데디 D3.js강의 2주차
Songyi Lim
 
꿈데디 D3.js강의 6주차
꿈데디 D3.js강의 6주차꿈데디 D3.js강의 6주차
꿈데디 D3.js강의 6주차
Songyi Lim
 
[week14] Getting started with D3.js
[week14] Getting started with D3.js[week14] Getting started with D3.js
[week14] Getting started with D3.js
neuroassociates
 
D3.js
D3.jsD3.js
D3.js
ymtech
 
문디 14주차 발제 scatter plot
문디 14주차 발제 scatter plot문디 14주차 발제 scatter plot
문디 14주차 발제 scatter plot
Min Jeong Cho
 
안드로이드스터디 7
안드로이드스터디 7안드로이드스터디 7
안드로이드스터디 7jangpd007
 
Drawing with data
Drawing with dataDrawing with data
Drawing with data
Min Jeong Cho
 
IndirectDraw with unity
IndirectDraw with unityIndirectDraw with unity
IndirectDraw with unity
Jung Suk Ko
 
3D Graphics 101
3D Graphics 1013D Graphics 101
3D Graphics 101
Leonardo YongUk Kim
 
[0129 박민근] direct x2d
[0129 박민근] direct x2d[0129 박민근] direct x2d
[0129 박민근] direct x2d
MinGeun Park
 
cuda포스터-박일남
cuda포스터-박일남cuda포스터-박일남
cuda포스터-박일남DzH QWuynh
 
[0602 박민근] Direct2D
[0602 박민근] Direct2D[0602 박민근] Direct2D
[0602 박민근] Direct2D
흥배 최
 
[Week5]R_scraping
[Week5]R_scraping[Week5]R_scraping
[Week5]R_scraping
neuroassociates
 
이산수학 C1 프로젝트 4
이산수학 C1 프로젝트 4이산수학 C1 프로젝트 4
이산수학 C1 프로젝트 4pkok15
 
2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdfkd19h
 

What's hot (20)

[Week13] D3.js_Bar Chart
[Week13] D3.js_Bar Chart[Week13] D3.js_Bar Chart
[Week13] D3.js_Bar Chart
 
[week12] D3.js_Basic
[week12] D3.js_Basic[week12] D3.js_Basic
[week12] D3.js_Basic
 
[week16] D3.js (Scale & axis)
[week16] D3.js (Scale & axis)[week16] D3.js (Scale & axis)
[week16] D3.js (Scale & axis)
 
[Week12] D3.js_Basic2
[Week12] D3.js_Basic2[Week12] D3.js_Basic2
[Week12] D3.js_Basic2
 
꿈데디 D3.js강의 2주차
꿈데디 D3.js강의 2주차꿈데디 D3.js강의 2주차
꿈데디 D3.js강의 2주차
 
꿈데디 D3.js강의 6주차
꿈데디 D3.js강의 6주차꿈데디 D3.js강의 6주차
꿈데디 D3.js강의 6주차
 
[week14] Getting started with D3.js
[week14] Getting started with D3.js[week14] Getting started with D3.js
[week14] Getting started with D3.js
 
D3.js
D3.jsD3.js
D3.js
 
문디 14주차 발제 scatter plot
문디 14주차 발제 scatter plot문디 14주차 발제 scatter plot
문디 14주차 발제 scatter plot
 
안드로이드스터디 7
안드로이드스터디 7안드로이드스터디 7
안드로이드스터디 7
 
Drawing with data
Drawing with dataDrawing with data
Drawing with data
 
IndirectDraw with unity
IndirectDraw with unityIndirectDraw with unity
IndirectDraw with unity
 
3D Graphics 101
3D Graphics 1013D Graphics 101
3D Graphics 101
 
[0129 박민근] direct x2d
[0129 박민근] direct x2d[0129 박민근] direct x2d
[0129 박민근] direct x2d
 
cuda포스터-박일남
cuda포스터-박일남cuda포스터-박일남
cuda포스터-박일남
 
[0602 박민근] Direct2D
[0602 박민근] Direct2D[0602 박민근] Direct2D
[0602 박민근] Direct2D
 
[Week5]R_scraping
[Week5]R_scraping[Week5]R_scraping
[Week5]R_scraping
 
이산수학 C1 프로젝트 4
이산수학 C1 프로젝트 4이산수학 C1 프로젝트 4
이산수학 C1 프로젝트 4
 
이산수학04
이산수학04이산수학04
이산수학04
 
2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf2012 Dm A0 04 Pdf
2012 Dm A0 04 Pdf
 

More from neuroassociates

Bloter 넥스트 저널리즘 스쿨 강의자료
Bloter 넥스트 저널리즘 스쿨 강의자료Bloter 넥스트 저널리즘 스쿨 강의자료
Bloter 넥스트 저널리즘 스쿨 강의자료
neuroassociates
 
[Week20] D3.js_Mapping
[Week20] D3.js_Mapping[Week20] D3.js_Mapping
[Week20] D3.js_Mapping
neuroassociates
 
[week8] 데이터읽어주는남자
[week8] 데이터읽어주는남자[week8] 데이터읽어주는남자
[week8] 데이터읽어주는남자
neuroassociates
 
[week7] 데이터읽어주는남자
[week7] 데이터읽어주는남자[week7] 데이터읽어주는남자
[week7] 데이터읽어주는남자
neuroassociates
 
[week6] 데이터읽어주는남자
[week6] 데이터읽어주는남자[week6] 데이터읽어주는남자
[week6] 데이터읽어주는남자
neuroassociates
 
[week9]R_statics
[week9]R_statics[week9]R_statics
[week9]R_statics
neuroassociates
 
[week7]R_Wrangling(2)
[week7]R_Wrangling(2)[week7]R_Wrangling(2)
[week7]R_Wrangling(2)
neuroassociates
 
[Week5]데이터읽어주는남자
[Week5]데이터읽어주는남자[Week5]데이터읽어주는남자
[Week5]데이터읽어주는남자
neuroassociates
 
[Week4]데이터읽어주는남자
[Week4]데이터읽어주는남자[Week4]데이터읽어주는남자
[Week4]데이터읽어주는남자
neuroassociates
 
[Week4] Google refine
[Week4] Google refine[Week4] Google refine
[Week4] Google refine
neuroassociates
 
[Week3]데이터읽어주는남자
[Week3]데이터읽어주는남자[Week3]데이터읽어주는남자
[Week3]데이터읽어주는남자
neuroassociates
 
[Week2]데이터읽어주는남자
[Week2]데이터읽어주는남자[Week2]데이터읽어주는남자
[Week2]데이터읽어주는남자
neuroassociates
 
꿈꾸는 데이터 디자이너 시즌2 교육 설명회 2부
꿈꾸는 데이터 디자이너 시즌2 교육 설명회 2부꿈꾸는 데이터 디자이너 시즌2 교육 설명회 2부
꿈꾸는 데이터 디자이너 시즌2 교육 설명회 2부
neuroassociates
 
꿈꾸는 데이터 디자이너 시즌2 교육설명회
꿈꾸는 데이터 디자이너 시즌2 교육설명회꿈꾸는 데이터 디자이너 시즌2 교육설명회
꿈꾸는 데이터 디자이너 시즌2 교육설명회
neuroassociates
 
꿈꾸는 데이터 디자이너 1기를 끝내며
꿈꾸는 데이터 디자이너 1기를 끝내며꿈꾸는 데이터 디자이너 1기를 끝내며
꿈꾸는 데이터 디자이너 1기를 끝내며
neuroassociates
 
[Week10] R graphics
[Week10] R graphics[Week10] R graphics
[Week10] R graphics
neuroassociates
 

More from neuroassociates (16)

Bloter 넥스트 저널리즘 스쿨 강의자료
Bloter 넥스트 저널리즘 스쿨 강의자료Bloter 넥스트 저널리즘 스쿨 강의자료
Bloter 넥스트 저널리즘 스쿨 강의자료
 
[Week20] D3.js_Mapping
[Week20] D3.js_Mapping[Week20] D3.js_Mapping
[Week20] D3.js_Mapping
 
[week8] 데이터읽어주는남자
[week8] 데이터읽어주는남자[week8] 데이터읽어주는남자
[week8] 데이터읽어주는남자
 
[week7] 데이터읽어주는남자
[week7] 데이터읽어주는남자[week7] 데이터읽어주는남자
[week7] 데이터읽어주는남자
 
[week6] 데이터읽어주는남자
[week6] 데이터읽어주는남자[week6] 데이터읽어주는남자
[week6] 데이터읽어주는남자
 
[week9]R_statics
[week9]R_statics[week9]R_statics
[week9]R_statics
 
[week7]R_Wrangling(2)
[week7]R_Wrangling(2)[week7]R_Wrangling(2)
[week7]R_Wrangling(2)
 
[Week5]데이터읽어주는남자
[Week5]데이터읽어주는남자[Week5]데이터읽어주는남자
[Week5]데이터읽어주는남자
 
[Week4]데이터읽어주는남자
[Week4]데이터읽어주는남자[Week4]데이터읽어주는남자
[Week4]데이터읽어주는남자
 
[Week4] Google refine
[Week4] Google refine[Week4] Google refine
[Week4] Google refine
 
[Week3]데이터읽어주는남자
[Week3]데이터읽어주는남자[Week3]데이터읽어주는남자
[Week3]데이터읽어주는남자
 
[Week2]데이터읽어주는남자
[Week2]데이터읽어주는남자[Week2]데이터읽어주는남자
[Week2]데이터읽어주는남자
 
꿈꾸는 데이터 디자이너 시즌2 교육 설명회 2부
꿈꾸는 데이터 디자이너 시즌2 교육 설명회 2부꿈꾸는 데이터 디자이너 시즌2 교육 설명회 2부
꿈꾸는 데이터 디자이너 시즌2 교육 설명회 2부
 
꿈꾸는 데이터 디자이너 시즌2 교육설명회
꿈꾸는 데이터 디자이너 시즌2 교육설명회꿈꾸는 데이터 디자이너 시즌2 교육설명회
꿈꾸는 데이터 디자이너 시즌2 교육설명회
 
꿈꾸는 데이터 디자이너 1기를 끝내며
꿈꾸는 데이터 디자이너 1기를 끝내며꿈꾸는 데이터 디자이너 1기를 끝내며
꿈꾸는 데이터 디자이너 1기를 끝내며
 
[Week10] R graphics
[Week10] R graphics[Week10] R graphics
[Week10] R graphics
 

[Week14] D3.js_Scale and Axis