2020-08-13
우선 lightweight-chart의 time(x축), price(y축) 관련 매뉴얼은 아래 링크를 참조 하기 바란다
time(x축): https://github.com/tradingview/lightweight-charts/blob/master/docs/time-scale.md
price(y축): https://github.com/tradingview/lightweight-charts/blob/master/docs/price-scale.md
전체 매뉴얼: https://github.com/tradingview/lightweight-charts/tree/master/docs

매뉴얼을 바탕으로 time과 price의 format 설정 예는 아래와 같다.
<div id="lightweight_div1"></div>

<script src="/post_inc/lightweight/lightweight3.js"></script>
<script type="text/javascript">
var chart = LightweightCharts.createChart($('#lightweight_div1')[0], {
	width: 400,
	height: 300,
})

chart.applyOptions({
	priceScale: {
		autoScale: true,
	},
	timeScale: { // time format - x축
		barSpacing: 20, // 그래프 사이의 간격
		tickMarkFormatter: (time, tickMarkType, locale) => {
			return time['year']+'-'+time['month']+'-'+time['day']
		},
	},

});

const candlestickSeries = chart.addCandlestickSeries({ priceScaleId: 'right' });
candlestickSeries.setData([{ close: 108.9974612905403, high: 121.20998259466148, low: 96.65376292551082, open: 104.5614412226746, time: {year: 2020, month: 7, day: 22} },
	{ close: 110.46815600023501, high: 111.3650273696516, low: 82.65543461471314, open: 110.16538466099634, time: {year: 2020, month: 7, day: 23} },
	{ close: 90.62131977740425, high: 109.19838270252615, low: 82.30106956144076, open: 105.03104735287424, time: {year: 2020, month: 7, day: 24} },
	{ close: 96.80120024431532, high: 101.92074283374939, low: 89.25819769856513, open: 89.25819769856513, time: {year: 2020, month: 7, day: 25} },
	{ close: 94.87113928076117, high: 104.12503365679314, low: 85.42405005240111, open: 104.12503365679314, time: {year: 2020, month: 7, day: 26} },
	{ close: 100.76494087674855, high: 102.60508417239113, low: 80.76268547064865, open: 92.93299948659636, time: {year: 2020, month: 7, day: 27} },
	{ close: 101.45855928883597, high: 110.26727325817173, low: 91.10348900896837, open: 93.4362185148034, time: {year: 2020, month: 7, day: 28} },
	{ close: 91.68871815146144, high: 103.73263644407702, low: 73.5329263610334, open: 92.96467883926464, time: {year: 2020, month: 7, day: 29} },
	{ close: 89.39633140354033, high: 101.06569518834237, low: 81.71149885084162, open: 83.08248758612376, time: {year: 2020, month: 7, day: 30} },
	{ close: 89.39633140354033, high: 101.06569518834237, low: 81.71149885084162, open: 83.08248758612376, time: {year: 2020, month: 7, day: 31} },
])

candlestickSeries.applyOptions({
	priceFormat: { // price format - y축
		type: 'custom',
		// minMove: 0.02,
		formatter: function(f){
			return '😃 '+ f
		},
	},
})
</script>