API
This page documents the public API surface for ChartSpire, including constructor options, runtime methods, and integration callbacks.
Stylesheet (required)
ChartSpire is published as a JS module plus a separate global stylesheet. Import the CSS once before creating a chart:
import { ChartSpire } from 'chartspire'
import 'chartspire/style.css'| Asset | Bundler | CDN (unpkg) |
|---|---|---|
| JavaScript | chartspire → dist/chartspire-ui.js (ESM) | chartspire/bundle.js → dist/chartspire-ui.umd.js (global chartspireui) |
| Stylesheet | chartspire/style.css → dist/chartspire-ui.css | chartspire/style.css |
CDN:
<script src="https://unpkg.com/chartspire/bundle.js"></script>
<link rel="stylesheet" href="https://unpkg.com/chartspire/style.css">See Getting Started — Stylesheet (required) for install, peer dependency, and framework notes.
Creating chart
Create a chart instance by passing a configuration object to new ChartSpire(...).
For most implementations, start with container, symbol, interval, dataFeed, and enabledSymbolTypes, then add optional features as needed.
new ChartSpire(
options: {
bottomBarEnabled?: boolean;
bottomBarIntervalEnabled?: boolean;
candleCloseTimerEnabled?: boolean;
candleTypeEnabled?: boolean;
chartExportEnabled?: boolean;
chartNavigationEnabled?: boolean;
container: string | HTMLElement;
dataFeed: DataFeed | string;
dataFeedInitialHistoricalBars?: number;
defaultOpenComponents?: ('watchlist' | 'orderbook' | 'trades' | 'objecttree')[];
enabledSymbolTypes: SYMBOL_TYPE[];
fontFamily?: string;
fontWeight?: 'lighter' | 'normal' | 'bold' | 'bolder' | number
fullscreenEnabled?: boolean;
indicators?: string[]
indicatorsEnabled?: boolean;
interval: Interval;
layoutLimit?: number;
layoutsEnabled?: boolean;
layoutUseExternalStorage?: boolean;
leftBarEnabled?: boolean;
locale?: string;
logoEnabled?: boolean;
menuPageClickCallback?: (page: MenuPage) => void;
menuPages?: MenuPage[];
menuPagesEnabled?: boolean;
multiChartDelay?: number;
multiChartEnabled?: boolean;
multiChartLimit?: number;
objectTreeEnabled?: boolean;
orderBookDepthVisualization?: 'amount' | 'cumulative';
orderBookEnabled?: boolean;
orderBookMaxRows?: number;
periods?: Interval[];
replayEnabled?: boolean;
rightBarEnabled?: boolean;
screenshotEnabled?: boolean;
settingsEnabled?: boolean;
styles?: DeepPartial<Styles>;
subscribedSymbolsURL?: string;
symbol: SymbolInfo;
symbolEnabled?: boolean;
symbolSearchOnKeyStroke?: boolean;
theme?: string;
themeCustom?: CustomTheme[];
themesEnabled?: boolean;
timezone?: string;
timezoneEnabled?: boolean;
topBarEnabled?: boolean;
topBarIntervalEnabled?: boolean;
tradesEnabled?: boolean;
tradesMaxRows?: number;
tradesTimeFormat?: '12h' | '24h';
watchListAmount?: number;
watchListEnabled?: boolean;
watchListHttp?: boolean;
watchListHttpBatchSize?: number;
watchListHttpInterval?: number;
watchListHttpMaxRetries?: number;
watchListHttpRetryEnabled?: boolean;
watchListSubscriptionDelayMs?: number;
watchListLimit?: number;
watchListUseExternalStorage?: boolean;
watermark?: string | Node;
}
) => ChartSpirebottomBarEnabledEnable/disable the entire bottom bar (default: true).bottomBarIntervalEnabledEnable/disable interval selector in the bottom bar (default: true). Replaces the formerintervalEnabledoption. Has no effect whenbottomBarEnabledisfalse.candleCloseTimerEnabledWhether to enable candle close timer on the price linecandleTypeEnabledEnable/disable candle type selector in the top bar (default: true)chartExportEnabledEnable/disable chart data CSV export button in the top bar (default: true)chartNavigationEnabledEnable/disable chart navigation controls (zoom, move, reset) (default: true)containerContainer id or HTML elementdataFeedData feed implementation or a registered data feed namedataFeedInitialHistoricalBarsNumber of historical bars to request on the initial chart load before scroll pagination starts (default: 500)defaultOpenComponentsArray of component names to open by default on page load. Maximum of 3 components. Valid values: 'watchlist', 'orderbook', 'trades', 'objecttree'. Components must be enabled to open (e.g., watchListEnabled: true)enabledSymbolTypesArray of SYMBOL_TYPE values to filter which symbol types are available in the UI. When specified, only these symbol types will appear in symbol search, watchlists, and other symbol-related features. If empty or omitted, all symbol types are available. Example: [SYMBOL_TYPE.STOCKS, SYMBOL_TYPE.CRYPTO]fontFamilyFont family for the entire chart (e.g., 'Roboto', 'Arial, sans-serif', '"Inter", system-ui, sans-serif')fontWeightFont weight for the entire chart (e.g., 'normal', 'bold', '400', '600')fullscreenEnabledEnable/disable fullscreen button in the top bar (default: true)indicatorsDefault indicators to display on the chart (e.g., ['SAR', 'VOL'])indicatorsEnabledEnable/disable the indicators button in the top bar (default: true)intervalTime intervallayoutLimitMaximum number of saved layoutslayoutsEnabledEnable/disable layout selector in bottom bar (default: true)layoutUseExternalStorageWhether to use external storage for layoutsleftBarEnabledEnable/disable the entire left bar (default: true).localeLanguagelogoEnabledEnable/disable ChartSpire logomenuPagesArray of menu pages to display in the topbar dropdown menumenuPagesEnabledEnable/disable the menu dropdown in the topbar (default: false)menuPageClickCallbackCallback function called when user clicks on a menu page - receives the selected page objectmultiChartDelayDelay in milliseconds between mounting/unmounting charts during multichart switchmultiChartEnabledEnable/disable multi-chart layout button in the top bar (default: true)multiChartLimitMaximum number of charts allowed (1, 2, 3, 4, 6, 8, 10, 12, 14, 16). Defaults to 16objectTreeEnabledWhether to enable the Object Tree component that displays chart properties, indicators, and overlays (default: true)orderBookDepthVisualizationOrder book depth visualization mode: 'amount' shows individual order quantities, 'cumulative' shows cumulative market depth (default: 'cumulative')orderBookEnabledWhether to enable order book functionalityorderBookMaxRowsMaximum number of rows to display in the order book (default: 10)periodsAll available time intervalsreplayEnabledEnable/disable replay button in the top bar (default: true)rightBarEnabledEnable/disable the entire right bar (default: true). Whenfalse, the right bar is hidden and chart content expands to fill the reclaimed horizontal space. Watchlist, order book, trades, and object tree UI in the right bar are unavailable unless you provide your own UI.screenshotEnabledEnable/disable screenshot button in the top bar (default: true)settingsEnabledEnable/disable settings button in the top bar (default: true)stylesCore chart stylessubscribedSymbolsURLURL for subscribed symbolssymbolSymbol information objectsymbolEnabledEnable/disable symbol display and symbol search trigger in the top bar (default: true)symbolSearchOnKeyStrokeEnable real-time symbol search that triggers on every keystroke (default: false). When enabled, search results update as you type. When disabled, search only triggers when Enter key is pressedthemeThemethemesEnabledEnable/disable theme selector in bottom bar (default: true)themeCustomCustom chart theme, for more details refer totheme.mddoctimezoneTimezonetimezoneEnabledEnable/disable timezone selector in bottom bar (default: true)topBarEnabledEnable/disable the entire top bar (default: true).topBarIntervalEnabledEnable/disable interval dropdown in the top bar (default: true)tradesEnabledWhether to enable trades (time and sales) functionalitytradesMaxRowsMaximum number of trade rows to display in the trades component (default: 50)tradesTimeFormatTime format for trade timestamps: '12h' for 12-hour format with AM/PM, '24h' for 24-hour format (default: '24h')watchListAmountNumber of watchlist items to displaywatchListEnabledWhether to enable watchlist functionalitywatchListHttpEnable HTTP polling for watchlist prices instead of WebSocket streaming (default: false)watchListHttpBatchSizeMaximum number of symbols to batch in a single HTTP request cycle (default: 10)watchListHttpIntervalInterval in milliseconds between HTTP price requests for watchlist (default: 5000, minimum: 1000)watchListHttpMaxRetriesMaximum number of retry attempts for failed HTTP requests (default: 3)watchListHttpRetryEnabledEnable retry logic for failed HTTP price requests (default: true)watchListSubscriptionDelayMsDelay in milliseconds between each symbol when the watchlist bulk-subscribes to the data feed (default: 0).watchListLimitMaximum number of items in the watchlistwatchListUseExternalStorageWhether to use external storage for watchlistwatermarkWatermark
SymbolInfo Interface
Defines the symbol payload shape used when creating charts, switching symbols, and integrating data feeds.
interface SymbolInfo {
symbol: string;
type: SYMBOL_TYPE | 'UNKNOWN';
name?: string;
shortName?: string;
exchange?: string;
market?: string;
pricePrecision?: number;
volumePrecision?: number;
priceCurrency?: string;
logo?: string;
}ChartID Interface
Represents a chart instance identifier in multi-chart mode for APIs that target a specific chart.
interface ChartID {
id: string;
}Chart API
These runtime methods let you control chart state after initialization (theme, symbol, interval, active chart, and lifecycle).
setTheme(theme)
(theme: string) => voidSet theme for all charts.
getTheme()
() => stringGet current theme.
setStyles(styles)
(styles: DeepPartial<Styles>) => voidSet core chart styles for all charts.
getStyles()
() => StylesGet core chart styles from active chart.
setLocale(locale)
(locale: string) => voidSet language for all charts.
getLocale()
() => stringGet language from active chart.
setFontFamily(fontFamily)
(fontFamily: string) => voidSet font family for the entire widget. Accepts any valid CSS font-family value.
Examples:
// Set Roboto font with fallbacks
chart.setFontFamily('Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif')
// Set custom font with fallbacks
chart.setFontFamily('"Inter", "Helvetica Neue", Arial, sans-serif')
// Set system font
chart.setFontFamily('system-ui, sans-serif')getFontFamily()
() => stringGet current font family setting.
setFontWeight(fontWeight)
(fontWeight: 'lighter' | 'normal' | 'bold' | 'bolder' | number) => voidSet font weight for the entire widget. Accepts any valid CSS font-weight value.
Examples:
// Set font weight using keywords
chart.setFontWeight('normal')
chart.setFontWeight('bold')
chart.setFontWeight('lighter')
// Set font weight using numeric values
chart.setFontWeight(400) // normal
chart.setFontWeight(600) // semi-bold
chart.setFontWeight(700) // boldgetFontWeight()
() => stringGet current font weight setting.
setTimezone(timezone)
(timezone: string) => voidSet timezone for all charts.
getTimezone()
() => stringGet timezone from active chart.
setSymbol(symbol, chartId, dataFeed)
(symbol: SymbolInfo, chartId: ChartID, dataFeed: DataFeed) => voidSet symbol for a specific chart.
getSymbol(chartId)
(chartId: ChartID) => SymbolInfo | nullGet symbol for a specific chart.
setInterval(interval, chartId)
(interval: Interval, chartId: ChartID) => voidSet interval for a specific chart.
getInterval(chartId)
(chartId: ChartID) => Interval | nullGet interval for a specific chart.
getActiveChart()
() => Nullable<ChartInterface>Get active chart.
getChart(chartId)
(chartId: ChartID) => Nullable<ChartInterface>Get chart for a specific chart ID.
isActiveChart(chartId)
(chartId: ChartID) => booleanCheck if a specific chart is active.
Default Open Components
The defaultOpenComponents property allows you to specify which right-side panel components should be open by default when the chart loads. This is useful for creating a customized initial view for your users.
Basic Usage
Use this pattern when you want one or more right-side panels open as soon as the widget mounts.
const chart = new ChartSpire({
// ... other options
// Enable the components you want to use
watchListEnabled: true,
orderBookEnabled: true,
tradesEnabled: true,
// Open watchlist and orderbook by default
defaultOpenComponents: ['watchlist', 'orderbook'],
})Available Components
These are the component keys accepted by defaultOpenComponents.
'watchlist'- Symbol watchlist panel'orderbook'- Order book panel'trades'- Recent trades panel'objecttree'- Object tree panel
Rules and Limitations
- Maximum of 3 components can be open at once
- Only enabled components will open (e.g., requires
watchListEnabled: truefor watchlist) - Components are opened in the order specified in the array
- If more than 3 components are specified, only the first 3 will be used
Examples
The examples below show common default-open combinations and a complete configuration.
// Open just the watchlist
defaultOpenComponents: ['watchlist']
// Open watchlist and orderbook
defaultOpenComponents: ['watchlist', 'orderbook']
// Open all three panels (max limit)
defaultOpenComponents: ['watchlist', 'orderbook', 'trades']
// This will only open the first 3 (excess ignored)
defaultOpenComponents: ['watchlist', 'orderbook', 'trades', 'objecttree']
// Complete configuration example
const chart = new ChartSpire({
container: '#chart',
symbol: { symbol: 'BTCUSDT', type: 'crypto' },
dataFeed: new DefaultDataFeed({
http: {
baseUrl: 'https://api.example.com',
endpoints: {
search: '/v1/market-data/symbols',
historical: '/v1/market-data/candles',
price: '/v1/market-data/price'
}
},
websocket: {
enabled: true,
url: 'wss://stream.example.com/v1/market-data'
}
}),
// Enable components
watchListEnabled: true,
orderBookEnabled: true,
tradesEnabled: true,
// Open watchlist and orderbook by default
defaultOpenComponents: ['watchlist', 'orderbook'],
// ... other options
})Theme API
Custom themes are registered via the themeCustom constructor option. See Theme Customization for the CustomTheme interface and examples.
setActiveChart(chartId)
(chartId: ChartID) => voidSet the active chart.
getMultiChart()
() => numberGet the current number of displayed charts.
getAllChartIds()
() => string[]Get an array of all chart IDs that are available based on the multiChartLimit.
getVisibleChartIds()
() => string[]Get an array of chart IDs that are currently visible based on the multiChart setting.
syncAllSymbolsToActiveChart()
() => voidSync all charts to use the symbol from the active chart. When called, all visible charts will switch to display the same symbol as the currently active chart, while preserving their individual interval settings.
syncAllIntervalsToActiveChart()
() => voidSync all charts to use the interval from the active chart. When called, all visible charts will switch to use the same time interval as the currently active chart, while preserving their individual symbols.
destroy()
() => voidClean up resources and remove all charts.