---
code: "DIS-14"
id: "c-vari"
tab: "distribution"
kind: "core"
title: "Variwide · 가변폭 막대"
library: "ECharts"
deps: ["echarts@5"]
load: "low"
pasteKind: "echarts-mount"
family: "composition"
dataShape: "category shares or weighted blocks"
tasks: ["show composition", "show frequency", "compare magnitudes", "show part-to-whole"]
tags: ["distribution", "비율", "빈도", "composition", "share", "variwide", "가변폭", "막대"]
gallery: "https://graph.heal7.com/#DIS-14"
js: "/sku/DIS-14.js"
---

# [DIS-14] Variwide · 가변폭 막대

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

## 언제 가져가나
막대 높이 = 값, 막대 폭 = 가중치(표본 수) — 두 지표를 한 면적으로.

**응용** 부서별 평균×인원, 국가별 GDP×인구.

## 데이터 모양
- family: `composition`
- dataShape: category shares or weighted blocks
- tasks: show composition, show frequency, compare magnitudes, show part-to-whole
- tags: distribution, 비율, 빈도, composition, share, variwide, 가변폭, 막대


## 의존
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 rows = [
    {name:'기획', avg:78, n:12},{name:'디자인', avg:84, n:8},
    {name:'개발', avg:72, n:24},{name:'데이터', avg:88, n:6},
    {name:'영업', avg:65, n:18},{name:'운영', avg:70, n:10}
  ];
  const totalN = rows.reduce((a,r)=>a+r.n,0);
  const cVari = reg('c-vari',{
    backgroundColor:T.bg,
    tooltip:{formatter: p => `${rows[p.dataIndex].name}<br/>평균 ${rows[p.dataIndex].avg}점 · 인원 ${rows[p.dataIndex].n}명`},
    grid:{top:18, right:14, bottom:36, left:36},
    xAxis:{type:'value', max:totalN, axisLabel:{show:false}, splitLine:{show:false}, axisTick:{show:false}, axisLine:{lineStyle:{color:T.grid}}},
    yAxis:{type:'value', max:100, axisLabel:{color:T.sub, fontSize:10}, splitLine:{lineStyle:{color:T.grid}}},
    series:[{
      type:'custom',
      renderItem:(p,api)=>{
        let acc=0; for(let k=0;k<api.value(0);k++) acc += rows[k].n;
        const r = rows[api.value(0)];
        const x0 = api.coord([acc,0])[0];
        const x1 = api.coord([acc + r.n,0])[0];
        const y0 = api.coord([0,0])[1];
        const y1 = api.coord([0, r.avg])[1];
        return {type:'rect', shape:{x:x0+3, y:y1, width:x1-x0-6, height:y0-y1, r:[6,6,0,0]},
          style:{fill:{type:'linear',x:0,y:0,x2:0,y2:1,colorStops:[{offset:0,color:T.gold},{offset:1,color:'rgba(232,192,105,.25)'}]}}};
      },
      data: rows.map((r,i)=>({value:[i, r.avg]}))
    }]
  });
  if(cVari){
    const drawLabels = () => {
      let acc=0;
      const elements = rows.map(r => {
        const mid = acc + r.n/2; acc += r.n;
        const px = cVari.convertToPixel({xAxisIndex:0}, mid);
        const py = cVari.getHeight() - 16;
        return {type:'text', left:px, top:py, style:{text:r.name, fill:T.sub, font:'10px Pretendard,system-ui', textAlign:'center'}};
      });
      cVari.setOption({graphic:{elements}});
    };
    cVari.on('finished', drawLabels);
    window.addEventListener('resize', () => setTimeout(drawLabels, 50));
  }
};
factory();
```

## 원본 factory (갤러리 정본 발췌)
- file: `frontend/js/graph-gallery/main.js`
- lines: 2901-2943
- gallery: https://graph.heal7.com/#DIS-14
- raw js: https://graph.heal7.com/sku/DIS-14.js

```js
function(){
  const rows = [
    {name:'기획', avg:78, n:12},{name:'디자인', avg:84, n:8},
    {name:'개발', avg:72, n:24},{name:'데이터', avg:88, n:6},
    {name:'영업', avg:65, n:18},{name:'운영', avg:70, n:10}
  ];
  const totalN = rows.reduce((a,r)=>a+r.n,0);
  const cVari = reg('c-vari',{
    backgroundColor:T.bg,
    tooltip:{formatter: p => `${rows[p.dataIndex].name}<br/>평균 ${rows[p.dataIndex].avg}점 · 인원 ${rows[p.dataIndex].n}명`},
    grid:{top:18, right:14, bottom:36, left:36},
    xAxis:{type:'value', max:totalN, axisLabel:{show:false}, splitLine:{show:false}, axisTick:{show:false}, axisLine:{lineStyle:{color:T.grid}}},
    yAxis:{type:'value', max:100, axisLabel:{color:T.sub, fontSize:10}, splitLine:{lineStyle:{color:T.grid}}},
    series:[{
      type:'custom',
      renderItem:(p,api)=>{
        let acc=0; for(let k=0;k<api.value(0);k++) acc += rows[k].n;
        const r = rows[api.value(0)];
        const x0 = api.coord([acc,0])[0];
        const x1 = api.coord([acc + r.n,0])[0];
        const y0 = api.coord([0,0])[1];
        const y1 = api.coord([0, r.avg])[1];
        return {type:'rect', shape:{x:x0+3, y:y1, width:x1-x0-6, height:y0-y1, r:[6,6,0,0]},
          style:{fill:{type:'linear',x:0,y:0,x2:0,y2:1,colorStops:[{offset:0,color:T.gold},{offset:1,color:'rgba(232,192,105,.25)'}]}}};
      },
      data: rows.map((r,i)=>({value:[i, r.avg]}))
    }]
  });
  if(cVari){
    const drawLabels = () => {
      let acc=0;
      const elements = rows.map(r => {
        const mid = acc + r.n/2; acc += r.n;
        const px = cVari.convertToPixel({xAxisIndex:0}, mid);
        const py = cVari.getHeight() - 16;
        return {type:'text', left:px, top:py, style:{text:r.name, fill:T.sub, font:'10px Pretendard,system-ui', textAlign:'center'}};
      });
      cVari.setOption({graphic:{elements}});
    };
    cVari.on('finished', drawLabels);
    window.addEventListener('resize', () => setTimeout(drawLabels, 50));
  }
}
```

