Skip to main content

Controlled & uncontrolled

Charts have preference state: resolution, skin, light/dark, up-down colors, timezone, locale. Each can be driven in two ways — pick one primary path.

Concepts

UncontrolledControlled
Source of truth (SSOT)Chart-internal storeHost App state / ref
How to changeIn-chart useKline* setXxxUpdate parent state, pass via props
Host must hold value?NoYes — keep passing current value and handle callbacks
Typical useToolbar only inside chartSync with URL / global settings / multi-chart / side UI
tip

You can mix: e.g. controlled resolution, uncontrolled theme. Don’t treat both sides as SSOT for the same preference.

How to use

Uncontrolled

  1. Optionally set initial values on KeisenChart (resolution="1", etc.)
  2. Call useKlineResolution (and friends) in header (or other chart subtree)
  3. Switch with returned setXxx; App should not also useState the same field, and need not wire onXxxChange

Controlled

  1. App holds current value with useState / ref
  2. Keep passing the matching prop (resolution={resolution})
  3. Wire onXxxChange / Vue @xxx-change to write chart changes back to App
  4. Side UI mutates App state; in-chart header can still use hooks (setXxx fires the callback)

Dual-mode APIs

PreferencepropReact callbackVue eventhook / composable
ResolutionresolutiononResolutionChangeresolution-changeuseKlineResolutionsetResolution
SkinthemeonThemeChangetheme-changeuseKlineThemesetTheme
Light/darkmodeonModeChangemode-changeuseKlineThemesetMode
Up/downupDownonUpDownChangeup-down-changeuseKlineThemesetUpDown
TimezonetimezoneonTimezoneChangetimezone-changeuseKlineTimezonesetTimezone
LocalelocaleonLocaleChangelocale-changeuseKlineLocalesetLocale

theme / mode / upDown are orthogonal; each can be controlled or uncontrolled independently.

Prop-only (no matching hook) — already owned by the host:

PropDescription
symbolInstrument held by host; change the prop
priceFormat / showDataPanelConfig via props
data / getData / onSubscribeData wiring, not display preferences

Uncontrolled example

App only passes initials; toolbar in header switches everything via hooks.

Loading interactive example…

Controlled example

App holds all preference state; external toolbar updates state, synced via props + onChange.

Loading interactive example…