---
code: "3D-04"
id: "c-cluster3d"
tab: "spatial"
kind: "core"
title: "3D Cluster · 클러스터 산점"
library: "ECharts-GL"
deps: ["echarts@5", "echarts-gl"]
load: "med"
pasteKind: "echarts-mount"
family: "spatial-3d"
dataShape: "3D coordinates, surfaces or paths"
tasks: ["inspect spatial form", "rotate perspective", "show structure", "compare profiles", "inspect shape in 3D"]
tags: ["3d", "spatial", "webgl", "multivariate", "cluster", "클러스터", "산점"]
gallery: "https://graph.heal7.com/#3D-04"
js: "/sku/3D-04.js"
---

# [3D-04] 3D Cluster · 클러스터 산점

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

## 언제 가져가나
카테고리별 색상으로 분리된 입체 군집 — 회전으로 분리도 확인.

**응용** K-means 결과, 페르소나 클러스터, 제품 군집.

## 데이터 모양
- family: `spatial-3d`
- dataShape: 3D coordinates, surfaces or paths
- tasks: inspect spatial form, rotate perspective, show structure, compare profiles, inspect shape in 3D
- tags: 3d, spatial, webgl, multivariate, cluster, 클러스터, 산점


## 의존
echarts@5, echarts-gl · load `med` · library `ECharts-GL`

## 붙여넣는 법
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 data = [];
  const centers = [[2,2,2],[5,5,5],[2,5,2],[5,2,5]];
  centers.forEach((cn,k)=>{ for(let i=0;i<60;i++) data.push([cn[0]+Math.random()*1.6-.8, cn[1]+Math.random()*1.6-.8, cn[2]+Math.random()*1.6-.8, k]); });
  reg('c-cluster3d', {
    backgroundColor:T.bg,
    xAxis3D:{type:'value', axisLabel:{color:T.sub,fontSize:9}}, yAxis3D:{type:'value', axisLabel:{color:T.sub,fontSize:9}}, zAxis3D:{type:'value', axisLabel:{color:T.sub,fontSize:9}},
    grid3D:{viewControl:{autoRotate:true, autoRotateSpeed:6}, axisLine:{lineStyle:{color:T.grid}}, splitLine:{lineStyle:{color:T.grid}}},
    series:[{type:'scatter3D', data, symbolSize:10,
      itemStyle:{color:p=>[T.gold,T.royal,T.rose,T.teal][p.data[3]], opacity:.85}}]
  });
};
factory();
```

## 원본 factory (갤러리 정본 발췌)
- file: `frontend/js/graph-gallery/main.js`
- lines: 1854-1865
- gallery: https://graph.heal7.com/#3D-04
- raw js: https://graph.heal7.com/sku/3D-04.js

```js
function(){
  const data = [];
  const centers = [[2,2,2],[5,5,5],[2,5,2],[5,2,5]];
  centers.forEach((cn,k)=>{ for(let i=0;i<60;i++) data.push([cn[0]+Math.random()*1.6-.8, cn[1]+Math.random()*1.6-.8, cn[2]+Math.random()*1.6-.8, k]); });
  reg('c-cluster3d', {
    backgroundColor:T.bg,
    xAxis3D:{type:'value', axisLabel:{color:T.sub,fontSize:9}}, yAxis3D:{type:'value', axisLabel:{color:T.sub,fontSize:9}}, zAxis3D:{type:'value', axisLabel:{color:T.sub,fontSize:9}},
    grid3D:{viewControl:{autoRotate:true, autoRotateSpeed:6}, axisLine:{lineStyle:{color:T.grid}}, splitLine:{lineStyle:{color:T.grid}}},
    series:[{type:'scatter3D', data, symbolSize:10,
      itemStyle:{color:p=>[T.gold,T.royal,T.rose,T.teal][p.data[3]], opacity:.85}}]
  });
}
```

