---
code: "INT-25"
id: "c-pierace"
tab: "dynamic-2"
kind: "interactive"
title: "Pie Race · 비중 레이스"
library: "ECharts"
deps: ["echarts@5"]
load: "med"
pasteKind: "echarts-mount"
family: "kpi"
dataShape: "headline value, rank race or progress state"
tasks: ["explore data", "filter subsets", "monitor change", "surface headline KPI"]
tags: ["interactive", "exploration", "linked view", "kpi", "progress", "pie", "race", "비중", "레이스"]
gallery: "https://graph.heal7.com/#INT-25"
js: "/sku/INT-25.js"
---

# [INT-25] Pie Race · 비중 레이스

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

## 언제 가져가나
2초마다 비중이 변하는 로즈 도넛 — 점유율 변동을 회전감 있게.

**응용** 시장 점유율 변화, 투표 진행 상황, 카테고리 트렌드.

## 데이터 모양
- family: `kpi`
- dataShape: headline value, rank race or progress state
- tasks: explore data, filter subsets, monitor change, surface headline KPI
- tags: interactive, exploration, linked view, kpi, progress, pie, 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-pierace'); if(!dom) return;
  const c = echarts.init(dom);
  const cats = ['A','B','C','D','E'];
  const colors = [T.gold, T.royal, T.rose, T.teal, T.plum];
  let vals = [30, 25, 20, 15, 10];
  function paint(){
    c.setOption({
      backgroundColor:T.bg, animationDurationUpdate:1500, animationEasingUpdate:'cubicInOut',
      legend:{data:cats, textStyle:{color:T.sub}, top:0, right:8},
      series:[{type:'pie', radius:['40%','78%'], center:['50%','58%'], roseType:'radius',
        label:{color:'#fff', fontSize:11, fontWeight:600, formatter:'{b}\n{c}'},
        labelLine:{lineStyle:{color:T.grid}},
        data: cats.map((n,i)=>({name:n, value:Math.round(vals[i]), itemStyle:{color:colors[i]}}))
      }]
    });
  }
  paint();
  setInterval(()=>{
    vals = vals.map(v => Math.max(5, Math.min(50, v + (Math.random()*10-5))));
    paint();
  }, 2000);
  charts.push(c);
};
factory();
```

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

```js
function(){
  const dom = document.getElementById('c-pierace'); if(!dom) return;
  const c = echarts.init(dom);
  const cats = ['A','B','C','D','E'];
  const colors = [T.gold, T.royal, T.rose, T.teal, T.plum];
  let vals = [30, 25, 20, 15, 10];
  function paint(){
    c.setOption({
      backgroundColor:T.bg, animationDurationUpdate:1500, animationEasingUpdate:'cubicInOut',
      legend:{data:cats, textStyle:{color:T.sub}, top:0, right:8},
      series:[{type:'pie', radius:['40%','78%'], center:['50%','58%'], roseType:'radius',
        label:{color:'#fff', fontSize:11, fontWeight:600, formatter:'{b}\n{c}'},
        labelLine:{lineStyle:{color:T.grid}},
        data: cats.map((n,i)=>({name:n, value:Math.round(vals[i]), itemStyle:{color:colors[i]}}))
      }]
    });
  }
  paint();
  setInterval(()=>{
    vals = vals.map(v => Math.max(5, Math.min(50, v + (Math.random()*10-5))));
    paint();
  }, 2000);
  charts.push(c);
}
```

