# 피벗 차트

- Human documentation: [https://docs.univer.ai/ko-KR/guides/sheets/features/pivot-chart](https://docs.univer.ai/ko-KR/guides/sheets/features/pivot-chart)

- Agent Markdown: [https://docs.univer.ai/ko-KR/guides/sheets/features/pivot-chart.md](https://docs.univer.ai/ko-KR/guides/sheets/features/pivot-chart.md)

- Requested language: `ko-KR`

- Content language: `ko-KR`

- Documentation version: `1.0.4`

- Source: [sheets/features/pivot-chart.ko-KR.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/sheets/features/pivot-chart.ko-KR.mdx)

---

[피벗 테이블](https://docs.univer.ai/ko-KR/guides/sheets/features/pivot-table.md)과 [차트](https://docs.univer.ai/ko-KR/guides/sheets/features/charts.md) 의존성을 등록한 뒤 통합 문서를 만들기 전에 아래 플러그인을 추가하세요. UI 언어 팩을 `locales`에 병합하고 스타일을 불러옵니다. Pro 라이선스가 필요합니다.

#### npm

```bash
npm install @univerjs-pro/sheets-pivot-chart @univerjs-pro/sheets-pivot-chart-ui
```

#### pnpm

```bash
pnpm add @univerjs-pro/sheets-pivot-chart @univerjs-pro/sheets-pivot-chart-ui
```

#### yarn

```bash
yarn add @univerjs-pro/sheets-pivot-chart @univerjs-pro/sheets-pivot-chart-ui
```

#### bun

```bash
bun add @univerjs-pro/sheets-pivot-chart @univerjs-pro/sheets-pivot-chart-ui
```

```ts
import { UniverSheetsPivotChartPlugin } from '@univerjs-pro/sheets-pivot-chart'
import { UniverSheetsPivotChartUIPlugin } from '@univerjs-pro/sheets-pivot-chart-ui'
import SheetsPivotChartLocale from '@univerjs-pro/sheets-pivot-chart-ui/locale/ko-KR'
import { LocaleType } from '@univerjs/core'

import '@univerjs-pro/sheets-pivot-chart/facade'
import '@univerjs-pro/sheets-pivot-chart-ui/lib/index.css'

univerAPI.loadLocales(LocaleType.KO_KR, SheetsPivotChartLocale)

univer.registerPlugin(UniverSheetsPivotChartPlugin)
univer.registerPlugin(UniverSheetsPivotChartUIPlugin)
```

Sheets Advanced 프리셋에는 두 플러그인이 포함되어 있습니다. Core 및 Drawing 프리셋과 함께 사용하고 API를 위해 `@univerjs-pro/sheets-pivot-chart/facade`를 명시적으로 가져오세요.

## 독립 보고서

차트가 보고서를 소유합니다. 삽입 후 행 필드와 값 필드를 추가합니다. 예제는 원본의 첫 두 열을 사용합니다.

```ts
const workbook = univerAPI.getActiveWorkbook()
const sheet = workbook?.getActiveSheet()
if (!sheet) throw new Error('No active worksheet')

sheet.getRange('A1:B4').setValues([
  ['Region', 'Sales'], ['East', 100], ['West', 200], ['East', 50],
])
const chart = await sheet.insertPivotChart(
  sheet.newPivotChart(univerAPI.Enum.ChartTypeString.Column)
    .setSource('A1:B4').setPosition('D2').setSize(640, 360).build(),
)
const fields = chart.getSourceFieldsInfo()
await chart.addField(fields[0].id, univerAPI.Enum.PivotTableFiledAreaEnum.Row, 0)
await chart.addField(fields[1].id, univerAPI.Enum.PivotTableFiledAreaEnum.Value, 0)
```

## 피벗 테이블 연결

필드, 필터, 정렬, 접기 변경은 참조 테이블과 다른 연결 차트에 공유됩니다. 모양과 위치는 독립적입니다. 차트를 삭제해도 테이블은 유지됩니다. 테이블을 삭제하면 차트가 비활성화되고 같은 테이블을 복원하면 다시 연결됩니다.

```ts
const pivotTable = workbook.getPivotTableById('pivot-table-1')
if (!pivotTable) throw new Error('PivotTable not found')

const linkedChart = await sheet.insertPivotChart(
  pivotTable.newChart(univerAPI.Enum.ChartTypeString.Line).setPosition('D22').build(),
)
linkedChart.setFieldButtonsVisible(true).setExpandCollapseButtonsVisible(true)
```

## 지원 유형과 Worker

꺾은선, 세로 막대, 가로 막대, 영역, 원형, 도넛 및 혼합 차트와 지원되는 누적 유형을 사용할 수 있습니다. 분산형, 거품형, 방사형, 폭포형 피벗 차트는 지원하지 않습니다. 원형은 첫 값 계열을, 도넛은 여러 계열을 사용합니다. 소계와 총계는 범주에서 제외됩니다.

[Worker](https://docs.univer.ai/ko-KR/guides/sheets/getting-started/worker.md)를 사용할 때 메인 스레드에는 `UniverSheetsAdvancedPreset({ useWorker: true })`, Worker에는 `UniverSheetsAdvancedWorkerPreset()`를 설정합니다. [패키지 설정](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/sheets-pivot-chart.md#worker-calculation)과 [FSheetPivotChart](https://docs.univer.ai/ko-KR/reference/facade/sheet-pivot-chart.md)를 참고하세요.

## 워크시트 복사 및 삭제

워크시트를 복사하면 피벗 차트도 새 ID로 복사됩니다. 독립 보고서의 원본이 복사 대상 시트에 있으면 새 시트와 독립 캐시를 사용합니다. 연결된 차트는 시트와 함께 복사된 피벗 테이블을 참조하며, 다른 시트에 대한 참조는 유지됩니다. 시트를 삭제하면 피벗 차트와 관련 리소스도 제거되고, 실행 취소 시 차트 정의와 원본 데이터가 복원됩니다.
