---
code: "INT-02"
id: "c-barrace"
tab: "dynamic-1"
kind: "interactive"
title: "Bar Race · 막대 레이스"
library: "ECharts"
deps: ["echarts@5"]
load: "med"
pasteKind: "echarts-mount"
family: "comparison"
dataShape: "ranked categories or before-after pairs"
tasks: ["explore data", "monitor change", "drill into structure", "surface headline KPI", "compare categories"]
tags: ["interactive", "live", "exploration", "kpi", "progress", "comparison", "ranking", "bar", "race", "막대", "레이스"]
gallery: "https://graph.heal7.com/#INT-02"
js: "/sku/INT-02.js"
---

# [INT-02] Bar Race · 막대 레이스

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

## 언제 가져가나
2초마다 갱신되는 순위 변동 막대 — 실시간 리더보드.

**응용** 분기별 매출 1위, 후보 키워드 상승률, 국가별 백신 보급.

## 데이터 모양
- family: `comparison`
- dataShape: ranked categories or before-after pairs
- tasks: explore data, monitor change, drill into structure, surface headline KPI, compare categories
- tags: interactive, live, exploration, kpi, progress, comparison, ranking, bar, race, 막대, 레이스


## 의존
echarts@5 · load `med` · 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-barrace'); if(!dom) return;
  const c = echarts.init(dom);
  const names = ['창의','분석','관계','실행','보호','혁신','통찰','도약'];
  const colors = [T.gold, T.royal, T.rose, T.teal, T.plum, '#f0a060', '#6dd2c4', '#cfd1d3'];
  let scores = names.map(()=>40+Math.random()*40);
  function paint(){
    const sorted = names.map((n,i)=>({n, v:scores[i], c:colors[i]})).sort((a,b)=>a.v-b.v);
    c.setOption({
      backgroundColor:T.bg, animationDuration:1400, animationDurationUpdate:1400, animationEasingUpdate:'cubicInOut',
      grid:{top:14,right:60,bottom:14,left:62},
      xAxis:{type:'value', max:100, axisLabel:{color:T.sub,fontSize:10}, splitLine:{lineStyle:{color:T.grid}}},
      yAxis:{type:'category', data:sorted.map(x=>x.n), axisLabel:{color:T.fg,fontSize:11,fontWeight:600}, axisLine:{show:false}, axisTick:{show:false}, animationDuration:1400, animationDurationUpdate:1400},
      series:[{type:'bar', barWidth:18, realtimeSort:true,
        label:{show:true, position:'right', color:T.gold, fontSize:11, fontWeight:700, formatter:p=>p.value.toFixed(0)},
        data: sorted.map(x=>({value:x.v, itemStyle:{color:x.c, borderRadius:[0,8,8,0]}}))
      }]
    });
  }
  paint();
  setInterval(()=>{ scores = scores.map(v => Math.max(20, Math.min(98, v + (Math.random()*16-8)))); paint(); }, 2000);
  charts.push(c);
};
factory();
```

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

```js
function(){
  const dom = document.getElementById('c-barrace'); if(!dom) return;
  const c = echarts.init(dom);
  const names = ['창의','분석','관계','실행','보호','혁신','통찰','도약'];
  const colors = [T.gold, T.royal, T.rose, T.teal, T.plum, '#f0a060', '#6dd2c4', '#cfd1d3'];
  let scores = names.map(()=>40+Math.random()*40);
  function paint(){
    const sorted = names.map((n,i)=>({n, v:scores[i], c:colors[i]})).sort((a,b)=>a.v-b.v);
    c.setOption({
      backgroundColor:T.bg, animationDuration:1400, animationDurationUpdate:1400, animationEasingUpdate:'cubicInOut',
      grid:{top:14,right:60,bottom:14,left:62},
      xAxis:{type:'value', max:100, axisLabel:{color:T.sub,fontSize:10}, splitLine:{lineStyle:{color:T.grid}}},
      yAxis:{type:'category', data:sorted.map(x=>x.n), axisLabel:{color:T.fg,fontSize:11,fontWeight:600}, axisLine:{show:false}, axisTick:{show:false}, animationDuration:1400, animationDurationUpdate:1400},
      series:[{type:'bar', barWidth:18, realtimeSort:true,
        label:{show:true, position:'right', color:T.gold, fontSize:11, fontWeight:700, formatter:p=>p.value.toFixed(0)},
        data: sorted.map(x=>({value:x.v, itemStyle:{color:x.c, borderRadius:[0,8,8,0]}}))
      }]
    });
  }
  paint();
  setInterval(()=>{ scores = scores.map(v => Math.max(20, Math.min(98, v + (Math.random()*16-8)))); paint(); }, 2000);
  charts.push(c);
}
```

