# FDocumentChart

> Language fallback: requested `zh-CN`; content is `en-US`.

- Human documentation: [https://docs.univer.ai/zh-CN/reference/facade/document-chart](https://docs.univer.ai/zh-CN/reference/facade/document-chart)

- Agent Markdown: [https://docs.univer.ai/zh-CN/reference/facade/document-chart.md](https://docs.univer.ai/zh-CN/reference/facade/document-chart.md)

- Requested language: `zh-CN`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [facade/document-chart.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/document-chart.mdx)

---

Live facade for an inserted Document Chart drawing.

## Access

Access through:

* [`FDocument.insertChart()`](https://docs.univer.ai/zh-CN/reference/facade/document.md#insertchart)
* [`FDocument.getChart()`](https://docs.univer.ai/zh-CN/reference/facade/document.md#getchart)
* [`FDocument.getCharts()`](https://docs.univer.ai/zh-CN/reference/facade/document.md#getcharts)

## Inheritance

Extends [`FChart`](https://docs.univer.ai/zh-CN/reference/facade/chart.md). Its inherited members are available on this object.

## Example

```ts
const fDocument = univerAPI.getActiveDocument()
const chartInfo = fDocument
  .newChart(univerAPI.Enum.ChartTypeString.Line)
  .setSource([
    ['Month', 'Sales'],
    ['Jan', 120],
    ['Feb', 180],
    ['Mar', 160],
  ])
  .setFloating()
  .setAbsolutePosition(120, 80)
  .setSize(640, 360)
  .setLineStyle({ width: 2 })
  .build()
const fChart = await fDocument.insertChart(chartInfo)

console.log(fChart.getId(), fChart.getDrawingId(), fChart.getInfo())
fChart.setTitle('Monthly sales').setAbsolutePosition(160, 100).setSize(720, 400)
await fChart.setDataSource([
  ['Month', 'Sales'],
  ['Apr', 200],
  ['May', 240],
  ['Jun', 220],
])

const updatedInfo = fChart
  .toBuilder(univerAPI.Enum.ChartTypeString.Area)
  .setSubtitle('Second quarter')
  .build()
await fChart.update(updatedInfo)
```

## Setup

Register [`@univerjs-pro/docs-chart`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-chart.md) or a preset that includes it. In plugin mode, import `@univerjs-pro/docs-chart/facade`. Additional methods below require their listed plugin packages. See [Facade setup](https://docs.univer.ai/zh-CN/guides/docs/getting-started/facade.md).

## `@univerjs-pro/docs-chart`

### `FDocumentChart.getDrawingId`

Returns the stable Document drawing identifier that hosts this Chart.

```typescript
getDrawingId(): string
```

**Returns**

The Document drawing identifier.

**Examples**

```ts
const fDocument = univerAPI.getActiveDocument()
const fChart = fDocument.getCharts()[0]
console.log(fChart.getDrawingId())
```

**Package:** [`@univerjs-pro/docs-chart`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-chart.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-chart@1.0.0-rc.0/lib/types/facade/f-document-chart.d.ts)

### `FDocumentChart.unitId`

The identifier of the Document that owns this Chart.

```typescript
readonly unitId: string
```

**Package:** [`@univerjs-pro/docs-chart`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/docs-chart.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-chart@1.0.0-rc.0/lib/types/facade/f-document-chart.d.ts)

## `@univerjs-pro/shape-thread-comment`

### `FDocumentChart.createCommentAsync`

Creates a comment anchored to this document chart.

```typescript
createCommentAsync(content: ThreadComment.ThreadCommentContent, options?: ElementComment.IFloatingElementCommentCreateOptions): Promise<boolean>
```

**Parameters**

* `content` — Required. Plain text or a Univer document body for rich comment content.
* `options` — Optional. Default: `{}`. Optional stable IDs, author, attachments, and creation time.

**Returns**

`true` when the create command succeeds; otherwise, `false`.

**Throws**

If the content is empty.

**Examples**

```ts
const chart = univerAPI.getActiveDocument()?.getCharts()[0]
await chart?.createCommentAsync('Verify the chart source.')
```

**Types:** [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64@7.0.2/lib/lib.es5.d.ts) · [`ThreadComment.ThreadCommentContent`](https://unpkg.com/@univerjs/thread-comment@1.0.0-rc.0/lib/types/services/thread-comment-api.service.d.ts) · [`ElementComment.IFloatingElementCommentCreateOptions`](https://unpkg.com/@univerjs-pro/shape-thread-comment@1.0.0-rc.0/lib/types/facade/element-comment.d.ts)

**Package:** [`@univerjs-pro/shape-thread-comment`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/shape-thread-comment.md) · [Type definitions](https://unpkg.com/@univerjs-pro/shape-thread-comment@1.0.0-rc.0/lib/types/facade/f-doc-chart.d.ts)

### `FDocumentChart.getComments`

Returns locally loaded comments anchored to this chart's drawing ID.

```typescript
getComments(): ThreadComment.IFacadeThreadCommentInfo[]
```

**Returns**

Matching comment threads in the current document.

**Examples**

```ts
const chart = univerAPI.getActiveDocument()?.getCharts()[0]
console.log(chart?.getComments().length ?? 0)
```

**Types:** [`ThreadComment.IFacadeThreadCommentInfo`](https://unpkg.com/@univerjs/thread-comment@1.0.0-rc.0/lib/types/services/thread-comment-api.service.d.ts)

**Package:** [`@univerjs-pro/shape-thread-comment`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/shape-thread-comment.md) · [Type definitions](https://unpkg.com/@univerjs-pro/shape-thread-comment@1.0.0-rc.0/lib/types/facade/f-doc-chart.d.ts)

### `FDocumentChart.listCommentsAsync`

Synchronizes known threads and returns comments anchored to this chart's drawing ID.

```typescript
listCommentsAsync(): Promise<ThreadComment.IFacadeThreadCommentInfo[]>
```

**Returns**

A promise resolving to matching synchronized comment threads.

**Examples**

```ts
const chart = univerAPI.getActiveDocument()?.getCharts()[0]
const comments = chart ? await chart.listCommentsAsync() : []
console.log(comments.length)
```

**Types:** [`ThreadComment.IFacadeThreadCommentInfo`](https://unpkg.com/@univerjs/thread-comment@1.0.0-rc.0/lib/types/services/thread-comment-api.service.d.ts) · [`Promise`](https://unpkg.com/@typescript/typescript-darwin-arm64@7.0.2/lib/lib.es5.d.ts)

**Package:** [`@univerjs-pro/shape-thread-comment`](https://docs.univer.ai/zh-CN/reference/packages/plugins/univerjs-pro/shape-thread-comment.md) · [Type definitions](https://unpkg.com/@univerjs-pro/shape-thread-comment@1.0.0-rc.0/lib/types/facade/f-doc-chart.d.ts)
