---
code: "INT-11"
id: "c-candle"
tab: "dynamic-1"
kind: "interactive"
title: "Candlestick · 캔들스틱"
library: "ECharts"
deps: ["echarts@5"]
load: "low"
pasteKind: "echarts-mount"
family: "financial"
dataShape: "ohlc candlestick with volume"
tasks: ["explore data", "monitor change", "drill into structure", "show price range"]
tags: ["interactive", "live", "exploration", "candlestick", "ohlc", "캔들스틱"]
gallery: "https://graph.heal7.com/#INT-11"
js: "/sku/INT-11.js"
---

# [INT-11] Candlestick · 캔들스틱

> AI 붙여넣기 카드. 갤러리 런타임(`main.js`)이 아니라 이 파일을 가져와라.

## 언제 가져가나
금융 차트의 표준 — OHLC 캔들 + 거래량 + 이동평균선.

**응용** 주가·코인 시세, 일일 변동성 추이, A/B 분포 일별.

## 데이터 모양
- family: `financial`
- dataShape: ohlc candlestick with volume
- tasks: explore data, monitor change, drill into structure, show price range
- tags: interactive, live, exploration, candlestick, ohlc, 캔들스틱


## 의존
echarts@5 · load `low` · library `ECharts`

## 붙여넣는 법
1. echarts 5.x 로드 (GL이면 echarts-gl도)
2. 컨테이너 id를 원본 id와 맞추거나 `document.getElementById` 한 줄만 바꾼다
3. `T`, `reg`, `cssv` 가 필요하면 갤러리 테마 스텁을 함께 가져간다

```js
const T = {
  "bg": "transparent",
  "fg": "#ece8f5",
  "sub": "#a59bbd",
  "grid": "rgba(255,255,255,.08)",
  "gold": "#e8c069",
  "royal": "#6b8cff",
  "rose": "#e07a9f",
  "teal": "#6dd2c4",
  "plum": "#b487e8"
};
const cssv = (n, fb) => (getComputedStyle(document.documentElement).getPropertyValue(n).trim() || fb);
const isDark = () => document.documentElement.getAttribute('data-theme') !== 'light';
const charts = [];
const reg = (id, opt) => {
  const dom = document.getElementById(id); if (!dom) return;
  const c = echarts.init(dom, null, {renderer:'canvas'});
  c.setOption(opt);
  charts.push(c);
  return c;
};
const factory = function(){
  const dom = document.getElementById('c-candle'); if(!dom) return;
  const c = echarts.init(dom);
  const dates = [], k = [], vol = [];
  let p = 100;
  for(let i=0;i<60;i++){
    const o = p, ch = (Math.random()-.48)*4;
    const cl = +(o+ch).toFixed(2);
    const hi = +Math.max(o,cl) + Math.random()*1.2;
    const lo = +Math.min(o,cl) - Math.random()*1.2;
    k.push([o, cl, +lo.toFixed(2), +hi.toFixed(2)]);
    vol.push(Math.round(60+Math.random()*140));
    p = cl;
    const d = new Date(2026,2,1+i); dates.push((d.getMonth()+1)+'.'+d.getDate());
  }
  // MA(5)
  const ma = k.map((_,i)=> i<4 ? '-' : +(k.slice(i-4,i+1).reduce((s,x)=>s+x[1],0)/5).toFixed(2));
  c.setOption({
    backgroundColor:T.bg, tooltip:{trigger:'axis', axisPointer:{type:'cross'}},
    legend:{data:['일봉','MA5','거래량'], textStyle:{color:T.sub}, top:0, right:8},
    grid:[
      {top:36, left:40, right:24, height:'58%'},
      {left:40, right:24, height:'18%', bottom:30}
    ],
    xAxis:[
      {type:'category', data:dates, axisLabel:{color:T.sub,fontSize:9}, axisLine:{lineStyle:{color:T.grid}}},
      {type:'category', gridIndex:1, data:dates, axisLabel:{show:false}, axisLine:{lineStyle:{color:T.grid}}}
    ],
    yAxis:[
      {scale:true, axisLabel:{color:T.sub,fontSize:10}, splitLine:{lineStyle:{color:T.grid}}},
      {gridIndex:1, axisLabel:{color:T.sub,fontSize:9}, splitLine:{show:false}}
    ],
    dataZoom:[{type:'inside', xAxisIndex:[0,1], start:40, end:100}],
    series:[
      {name:'일봉', type:'candlestick', data:k, itemStyle:{color:T.gold, color0:T.royal, borderColor:T.gold, borderColor0:T.royal}},
      {name:'MA5', type:'line', data:ma, smooth:true, symbol:'none', lineStyle:{color:T.rose, width:1.6}},
      {name:'거래량', type:'bar', xAxisIndex:1, yAxisIndex:1, data:vol, itemStyle:{color:p=>p.dataIndex>0 && k[p.dataIndex][1]>=k[p.dataIndex][0] ? 'rgba(232,192,105,.55)' : 'rgba(107,140,255,.55)'}}
    ]
  });
  charts.push(c);
};
factory();
```

## 원본 factory (갤러리 정본 발췌)
- file: `frontend/js/graph-gallery/main.js`
- lines: 1376-1416
- gallery: https://graph.heal7.com/#INT-11
- raw js: https://graph.heal7.com/sku/INT-11.js

```js
function(){
  const dom = document.getElementById('c-candle'); if(!dom) return;
  const c = echarts.init(dom);
  const dates = [], k = [], vol = [];
  let p = 100;
  for(let i=0;i<60;i++){
    const o = p, ch = (Math.random()-.48)*4;
    const cl = +(o+ch).toFixed(2);
    const hi = +Math.max(o,cl) + Math.random()*1.2;
    const lo = +Math.min(o,cl) - Math.random()*1.2;
    k.push([o, cl, +lo.toFixed(2), +hi.toFixed(2)]);
    vol.push(Math.round(60+Math.random()*140));
    p = cl;
    const d = new Date(2026,2,1+i); dates.push((d.getMonth()+1)+'.'+d.getDate());
  }
  // MA(5)
  const ma = k.map((_,i)=> i<4 ? '-' : +(k.slice(i-4,i+1).reduce((s,x)=>s+x[1],0)/5).toFixed(2));
  c.setOption({
    backgroundColor:T.bg, tooltip:{trigger:'axis', axisPointer:{type:'cross'}},
    legend:{data:['일봉','MA5','거래량'], textStyle:{color:T.sub}, top:0, right:8},
    grid:[
      {top:36, left:40, right:24, height:'58%'},
      {left:40, right:24, height:'18%', bottom:30}
    ],
    xAxis:[
      {type:'category', data:dates, axisLabel:{color:T.sub,fontSize:9}, axisLine:{lineStyle:{color:T.grid}}},
      {type:'category', gridIndex:1, data:dates, axisLabel:{show:false}, axisLine:{lineStyle:{color:T.grid}}}
    ],
    yAxis:[
      {scale:true, axisLabel:{color:T.sub,fontSize:10}, splitLine:{lineStyle:{color:T.grid}}},
      {gridIndex:1, axisLabel:{color:T.sub,fontSize:9}, splitLine:{show:false}}
    ],
    dataZoom:[{type:'inside', xAxisIndex:[0,1], start:40, end:100}],
    series:[
      {name:'일봉', type:'candlestick', data:k, itemStyle:{color:T.gold, color0:T.royal, borderColor:T.gold, borderColor0:T.royal}},
      {name:'MA5', type:'line', data:ma, smooth:true, symbol:'none', lineStyle:{color:T.rose, width:1.6}},
      {name:'거래량', type:'bar', xAxisIndex:1, yAxisIndex:1, data:vol, itemStyle:{color:p=>p.dataIndex>0 && k[p.dataIndex][1]>=k[p.dataIndex][0] ? 'rgba(232,192,105,.55)' : 'rgba(107,140,255,.55)'}}
    ]
  });
  charts.push(c);
}
```

