1.3 Multi Y Axis

3

Multi Y축

여러개의 시리즈 중 기준 Y축을 분리 할 수 있습니다.

  • 축이 두개이므로 사용되는 시리즈도 두 개 이상이 필요합니다.
  • 바시리즈는 멀티축이 지원되지 않습니다.

options listMidnighttruejs
var options = {
	data: {
		data: [
			{ Date: '20140101', Mprc: 10000, Cprc: 30000 },
			{ Date: '20140102', Mprc: 20000, Cprc: 30000 },
			{ Date: '20140103', Mprc: 15000, Cprc: 31000 },
			{ Date: '20140104', Mprc: 30000, Cprc: 30300 },
			{ Date: '20140105', Mprc: 5000, Cprc: 20000 }
		]
	},
	format: {
		xAxis: function(_str){
			return _str.substr(0, 4)+'.'+_str.substr(4,2)+'.'+_str.substr(6,2);
		},
		yAxis: 'priceDataFormat'
	},
	func: {
		tip: function(tipElement, data, rect){
			var date = data.xaxis.substr(0, 4)+'.'+data.xaxis.substr(4, 2)+'.'+data.xaxis.substr(6, 2);
			var tip = '<div class="text">'+date + ' / ' + String(data.yaxis).format().trim()+'</div>';
			tipElement.html(tip).show();
			var arrow = '<div class="arrow" style="width: '+tipElement.width() + 'px;"></div>';
			tipElement.html(tipElement.html() + arrow).css({
				left: rect.x - (tipElement.width() / 2), top: rect.y - 35
			});
		}
	},
	use: {
		animate: true,
		aCrossLine: true,
		multiYAxis: true
	}
};
var styles = {
	main: {
		layout: {
			paddingTop: 57, color: '#f8f8f8',
			line: {color: '#eaeaea', width: 1}
		},
		graph: {
			color: '#f8f8f8',
			line: {
				top: {color: '#cccccc'},
				left: {width: 0},
				right: {width: 0},
				bottom: {color: '#cccccc'}
			}
		},
		crossLine: {
			color: '#465866'
		},
		xAxis: {
			paddingTop: 13, height: 30,
			text: {family: 'Nanum Gothic', size: 12, color: '#666'},
			line: {color: '#e3e3e3', width: 1}
		},
		yAxis: {
			line: {color: '#cccccc', width: 1, opacity: 1}
		},
		tip: {
			className: 'tip'
		},
		series: {
			s1: {
				yAxis: {
					position: 'left',
					text: {family: 'Nanum Gothic', size: 12, color: '#666', align: 'right'}
				},
				area: {
					normal: {
						color: [ [0, '#2bcdba'], [100, '#6bdccf'] ],
						over: { color: [ [0, '#028c8e'], [100, '#33a2a4'] ] }
					}
				},
				line: {
					normal: {
						width: 0,
						over: { width: 0 }
					}
				},
				gradient: {
					direction: 'vertical'
				}
			},
			s2: {
				yAxis: {
					position: 'right',
					text: {family: 'Nanum Gothic', size: 12, color: '#666', align: 'left'}
				},
				area: {
					normal: {
						color: [ [0, '#feb401'], [100, '#fecb4e'] ],
						over: { color: [ [0, '#f28402'], [100, '#f59c33'] ] }
					}
				},
				line: {
					normal: {
						width: 0,
						over: { width: 0 }
					}
				},
				gradient: {
					direction: 'vertical'
				}
			}
		}
	}
};
var series = {
	"main": {
		"s1": {series: 'column', xaxis: 'Date', yaxis: 'Mprc'},
		"s2": {series: 'column', xaxis: 'Date', yaxis: 'Cprc'}
	}
};
var chart = webponent.chart.init($('.chart01'), options, styles, series);

 Demo

Example

멀티축 설정시 주의사항

options setting

옵션 설정 중 use.multiYAxis = true;로  변경해주어야 한다.

styles setting

멀티 Y축의 기준이 되는 SERIES 들이 있는데 그 Style SERIES 안에 yAxis: {...} 를 설정한다.

Parameters 

   defaulttype설명
yAxis










width 60number기준 Y축의 넓이
position 'left'string좌, 우 Y축중에 기준 Y축의 위치 ['left', 'right']
paddingLeft 10numberY축 Label의 왼쪽 여백
paddingRight 10numberY축 Label의 오른쪽 여백
baseAtZero falseboolean

false 인 경우 Y축은 최소값을 기준으로 표현되며,

true 인 경우 Y축은 0을 기준으로 한다.

maxNumber nullnumberY축의 최대값을 지정하고 싶을때 숫자값을 입력한다.
minNumber nullnumberY축의 최소값을 지정하고 싶을때 숫자값을 입력한다.
fit falseboolean

Y축의 Interval을 소수점 단위까지 보여주고 싶을때 사용한다.

false 이면 1단위(Default)로 interval 된다.

options의 format.yAxis와는 다른 것으로 주로 Y축의 최대값과 최소값의 차이가

0보다 크고 5 미만일때 Y축 inverval의 간격을 여과없이 보여주고자 사용한다.

useValueminfalseboolean제일 처음 값 출력 여부
maxfalseboolean제일 마지막 값 출력 여부
textfamily'dotum'string글꼴 종류 이름(영문명)
 size12number글꼴 크기(px 단위)
 color'#aaa'string글꼴 색상(영문 색상명 혹은 RGB값)
 align'left'

'string'

label width 내에서의 텍스트 위치['left', 'right', 'center']
 style

'normal'

'string'글꼴 모양['normal', 'bold', 'italic']
 opacity1number글꼴 투명도 (0~1)
 formatnullfunction

Y축 텍스트 Formatting

  •  멀티축의 기준이 되는 시리즈에 적용
  • options.format.yAxis 는 삭제되거나 null로 정의되어 있어야 한다.

series setting

멀티 Y축의 기준이 되는 SERIES 들이 있는데 그 SERIES에 yaxisid = '기준이 되는 Series KEY 명' 을 입력한다.

  • 왼쪽이나 오른쪽 중 Y축을 기준삼는 시리즈가 하나씩이면 yaxisid 는 정의해 주지 않아도 된다.
  • yaxisid는 한쪽 Y축을 기준으로 잡는 시리즈가 두개 이상일 경우에만 필히 지정해 주어야 한다.
options listMidnighttruejs
var options = {
	use: {
		multiYAxis: true
	}
};
var styles = {
	main: {
		series: {
			s1: {
				yAxis: {
					position: 'left'
				}
			},
			s2: {
				yAxis: {
					position: 'right'
				}
			},
			s3: {
 
			}
		}
	}
};
var series = {
	main: {
		s1: { series: 'line', xaxis: 'x축 데이터 key', yaxis: 'y축 데이터 key', yaxisid: 's1' }, // 기준이 되는 series 하나만 사용 될 경우 yaxisid는 적지 않아도 된다. 
		s2: { series: 'line', xaxis: 'x축 데이터 key', yaxis: 'y축 데이터 key', yaxisid: 's2' }, 
		s3: { series: 'line', xaxis: 'x축 데이터 key', yaxis: 'y축 데이터 key', yaxisid: 's2' }  // 기준이 되는 series의 key 명을 입력한다.
	}
}; 

Example 2)


Demo

Example

Example 3)


Demo

Example