API 参考

FCandlestickChartBuilder

本 API 页面目前提供英文正文。代码签名与标识符不随界面语言变化。

Fluent semantic builder for one HLC or OHLC Candlestick series.

Each source row represents one trading interval. Map one category field and four distinct numeric fields in Open, High, Low, Close order, or three in High, Low, Close order. A row with any missing or non-finite required price renders as a gap. Three roles mean HLC; four mean OHLC. Missing prices never change roles, and HLC never fabricates Open.

Sheet Header belongs to the source. Doc/Slide use setSource() for raw rows and setDataSource() to update an inserted chart; explicit Lite Header belongs to the host resource context. Both project titles into dataset dimensions. ChartContext only selects dataset indexes and does not store Header. An inline resource containing a title row uses host context { orient: 'row', header: { band: { startOffset: 0, endOffset: 0 } } }. The following Doc/Slide examples pass body rows directly, with no title band.

Inheritance

Extends FAxisChartBuilder. Its inherited members are available on this object.

Example

Sheet HLC with an explicit title band

TypeScript
const chartInfo = fWorksheet  .newChart(univerAPI.Enum.ChartTypeString.Candlestick)  .setSource({    range: 'A1:D6',    orientation: univerAPI.Enum.ChartSourceOrientation.Columns,    header: { band: { startOffset: 0, endOffset: 0 } },  })  .setCategoryField(0)  .setCandlestickFields({ highIndex: 1, lowIndex: 2, closeIndex: 3 })  .setHighLowLineStyle({ border: { color: '#333333', width: 1 } })  .setCloseMarkerStyle({ point: { shape: univerAPI.Enum.ChartLinePointShape.Dash, size: 8 } })  .build()// clearHighLowLineStyle()/clearCloseMarkerStyle() restore the default appearance.

Sheet

TypeScript
const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')const chartInfo = fWorksheet  .newChart(univerAPI.Enum.ChartTypeString.Candlestick)  .setSource({    range: 'A1:E8',    orientation: univerAPI.Enum.ChartSourceOrientation.Columns,    header: { band: { startOffset: 0, endOffset: 0 } },  })  .setCategoryField(0)  .setCandlestickFields({ openIndex: 1, highIndex: 2, lowIndex: 3, closeIndex: 4 })  .setRisingStyle({ color: '#0DA471', hollow: true })  .setFallingStyle({ color: '#F05252' })  .setDojiStyle({ color: '#8C8C8C', border: { width: 2 } })  .setCandleWidth(18)  .build()await fWorksheet.insertChart(chartInfo)

Doc

TypeScript
const fDocument = univerAPI.getActiveDocument()const chartInfo = fDocument  .newChart(univerAPI.Enum.ChartTypeString.Candlestick)  .setSource([    ['Mon', 112, 96, 108],    ['Tue', 116, 102, 105],  ])  .setCategoryField(0)  .setCandlestickFields({ highIndex: 1, lowIndex: 2, closeIndex: 3 })  .setHighLowLineStyle({ border: { color: '#333333', width: 1 } })  .setCloseMarkerStyle({ point: { shape: univerAPI.Enum.ChartLinePointShape.Dot, size: 8 } })  .build()await fDocument.insertChart(chartInfo)

Slide

TypeScript
const fPresentation = univerAPI.getActivePresentation()const fSlide = fPresentation.getSlideByIndex(0)const chartInfo = fSlide  .newChart(univerAPI.Enum.ChartTypeString.Candlestick)  .setSource([    ['Mon', 100, 112, 96, 108],    ['Tue', 108, 116, 102, 105],  ])  .setCategoryField(0)  .setCandlestickFields({ openIndex: 1, highIndex: 2, lowIndex: 3, closeIndex: 4 })  .setRisingStyle({ color: '#0DA471', hollow: true })  .setFallingStyle({ color: '#F05252' })  .setDojiStyle({ color: '#8C8C8C', border: { width: 2 } })  .setCandleWidth(18)  .build()await fSlide.insertChart(chartInfo)

Board

TypeScript
const fBoard = univerAPI.getActiveBoard()const chartInfo = fBoard  .newChart(univerAPI.Enum.ChartTypeString.Candlestick)  .setSource([    ['Mon', 100, 112, 96, 108],    ['Tue', 108, 116, 102, 105],  ])  .setCategoryField(0)  .setCandlestickFields({ openIndex: 1, highIndex: 2, lowIndex: 3, closeIndex: 4 })  .setRisingStyle({ color: '#0DA471', hollow: true })  .setFallingStyle({ color: '#F05252' })  .setDojiStyle({ color: '#8C8C8C', border: { width: 2 } })  .setCandleWidth(18)  .build()await fBoard.insertChart(chartInfo)

Setup

Register @univerjs-pro/engine-chart or a preset that includes it. In plugin mode, import @univerjs-pro/engine-chart/facade. Additional methods below require their listed plugin packages. See Facade setup.

@univerjs-pro/engine-chart

FCandlestickChartBuilder.clearCandlestickFields

Clears the atomic Candlestick mapping while preserving the category field.

TypeScript
clearCandlestickFields(): this

Returns

This builder for chaining.

Examples

TypeScript
builder.clearCandlestickFields()

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.clearCloseMarkerStyle

Clears authored Close marker appearance.

TypeScript
clearCloseMarkerStyle(): this

Examples

builder.clearCloseMarkerStyle();

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.clearDojiStyle

Clears explicit Doji style overrides so runtime defaults apply.

TypeScript
clearDojiStyle(): this

Returns

This builder for chaining.

Examples

TypeScript
builder.clearDojiStyle()

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.clearFallingStyle

Clears explicit Falling style overrides so runtime defaults apply.

TypeScript
clearFallingStyle(): this

Returns

This builder for chaining.

Examples

TypeScript
builder.clearFallingStyle()

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.clearHighLowLineStyle

Clears authored high-low appearance.

TypeScript
clearHighLowLineStyle(): this

Examples

builder.clearHighLowLineStyle();

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.clearRisingStyle

Clears explicit Rising style overrides so runtime defaults apply.

TypeScript
clearRisingStyle(): this

Returns

This builder for chaining.

Examples

TypeScript
builder.clearRisingStyle()

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.resetCandleWidth

Removes the fixed candle width so the renderer chooses it automatically.

TypeScript
resetCandleWidth(): this

Returns

This builder for chaining.

Examples

TypeScript
builder.resetCandleWidth()

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.setCandlestickFields

Replaces High, Low, Close, and optionally Open source fields atomically.

Category remains configured through setCategoryField(). Every supplied index must be a unique non-negative integer. Read the pending or persisted value with builder.build().config.mapping?.candlestick.

TypeScript
setCandlestickFields(fields: IChartCandlestickMappingSpec): this

Parameters

  • fields — Required. HLC indexes; omit Open for HLC or supply a real Open index for OHLC.

Returns

This builder for chaining.

Examples

TypeScript
builder  .setCategoryField(0)  .setCandlestickFields({ openIndex: 1, highIndex: 2, lowIndex: 3, closeIndex: 4 })const mapping = builder.build().config.mapping?.candlestick

Types: IChartCandlestickMappingSpec

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.setCandleWidth

Sets a fixed candle width value without Facade range validation.

TypeScript
setCandleWidth(width: number): this

Parameters

  • width — Required. Fixed candle width in pixels.

Returns

This builder for chaining.

Examples

TypeScript
builder.setCandleWidth(18)

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.setCloseMarkerStyle

Sets Close marker appearance.

TypeScript
setCloseMarkerStyle(style: NonNullable<IChartCandlestickSpec['closeMarker']>): this

Parameters

  • style — Required.

Examples

builder.setCloseMarkerStyle({ point: { size: 8 } });

Types: NonNullable · IChartCandlestickSpec

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.setDojiStyle

Sets semantic Doji body and wick style overrides.

TypeScript
setDojiStyle(style: IChartCandlestickStateStyleSpec): this

Parameters

  • style — Required. Doji body and wick style values, passed through without Facade range validation.

Returns

This builder for chaining.

Examples

TypeScript
builder.setDojiStyle({ color: '#8C8C8C', border: { width: 2 } })

Types: IChartCandlestickStateStyleSpec

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.setFallingStyle

Sets semantic Falling candle body and wick style overrides.

TypeScript
setFallingStyle(style: IChartCandlestickStateStyleSpec): this

Parameters

  • style — Required. Falling body and wick style values, passed through without Facade range validation.

Returns

This builder for chaining.

Examples

TypeScript
builder.setFallingStyle({ color: '#F05252' })

Types: IChartCandlestickStateStyleSpec

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.setHighLowLineStyle

Sets high-low line appearance.

TypeScript
setHighLowLineStyle(style: NonNullable<IChartCandlestickSpec['highLowLine']>): this

Parameters

  • style — Required.

Examples

builder.setHighLowLineStyle({ visible: false });

Types: NonNullable · IChartCandlestickSpec

Package: @univerjs-pro/engine-chart · Type definitions

FCandlestickChartBuilder.setRisingStyle

Sets semantic Rising candle body and wick style overrides.

TypeScript
setRisingStyle(style: IChartCandlestickStateStyleSpec): this

Parameters

  • style — Required. Rising body and wick style values, passed through without Facade range validation.

Returns

This builder for chaining.

Examples

TypeScript
builder.setRisingStyle({ color: '#0DA471', hollow: true })

Types: IChartCandlestickStateStyleSpec

Package: @univerjs-pro/engine-chart · Type definitions

你觉得这篇文档如何?

© 2026 DreamNum Co., Ltd.