Skip to main content

newSimpleChartWidget

newSimpleChartWidget is a constructor function for creating the Simple Chart widget.

Widget Constructor​

Call newSimpleChartWidget to create a widget instance inside a browser DOM element.

import { newSimpleChartWidget } from '@dx-display/widgets-simple-chart'

const domNode = document.getElementById('widget-container')
const dataProviders = {
ipfPath: '/your-path/ipf',
ipfAuthHeader: 'your-header',
feedPath: 'wss://your-path/feed',
feedAuthHeader: 'your-header',
schedulePath: '/api/schedule'
}
const widget = newSimpleChartWidget({
element: domNode,
providers: dataProviders,
})

Signature​

newSimpleChartWidget(props: WidgetConstructorProps): WidgetAPI

Returns​

An WidgetAPI object.

WidgetConstructorProps​

NameTypeDescription
elementHTMLElementA DOM element where the widget should be attached.
providersProvidersAn object with configuration for data providers. Refer to the Data Providers section for details
config optionalConfigInitial configuration of the widget
state optionalStateInitial state of the widget
theme optionalThemeName | ThemeInitial theme of the widget. Refer to the Styling section for details

Widget API​

getConfig​

Gets the current widget config.

Signature​

getConfig(): Config

Returns​

Config


setConfig​

Sets widget config.

Signature​

setConfig(config: Config): void

Parameters​

NameTypeDescription
configConfigConfiguration object. Omitted or undefined properties will be set to default

getState​

Gets the current widget state.

Signature​

getState(): State

Returns​

State


updateState​

Updates widget state.

Signature​

updateState(state: Partial<State>): void

Parameters​

NameTypeDescription
statePartial<State>State object. Merges with the previous state object.

addStateListener​

Sets up a function that will be called whenever the state or specified field is changed.

Signature​

addStateListener(stateChangeCallback: (state: State) => void): void
addStateListener(field: keyof State, fieldChangeCallback: (field: State[keyof State]) => void): void

Parameters​

NameTypeDescription
stateChangeCallback(state: State) => voidFunction that will be called whenever the state is changed.

Or

NameTypeDescription
fieldkeyof StateThe state field to listen for.
fieldChangeCallback(value: State[keyof State]) => voidFunction that will be called whenever the specified field is changed.

removeStateListener​

Removes an state listener previously registered with addStateListener

Signature​

removeStateListener(stateChangeCallback: (state: State) => void): void
removeStateListener(field: keyof State, fieldChangeCallback: (field: State[keyof State]) => void): void

Parameters​

NameTypeDescription
stateChangeCallback(state: State) => voidListener that will be removed.

Or

NameTypeDescription
fieldkeyof StateThe state field for which to remove a listener.
fieldChangeCallback(value: State[keyof State]) => voidListener that will be removed.

setSlot​

Inserts custom markup into widget UI. Refer to the Extend widget UI section for details.

Signature​

setSlot(slot: Slot, element: HTMLElement): void

Parameters​

NameTypeDescription
slotSlotThe place where a provided element is inserted.
elementHTMLElementAn element that is inserted.

setTheme​

Sets widget theme.

Signature​

setTheme(theme: Theme | ThemeName): void

unmount​

Destroys the widget.

Signature​

unmount(): void

Data Providers​

The Data Providers object supplies an information about the endpoints required by the widget, such as the path to the endpoint and the authorization key.

interface SimpleChartWidgetDataProviders {
ipfPath: string
ipfAuthHeader: string
feedPath: string
feedAuthHeader: string
schedulePath: string
}

Properties​

NameTypeDescription
ipfPathstringA string containing the path to the endpoint.
ipfAuthHeaderstringA string containing the authentication header for the endpoint.
feedPathstringA string containing the path to the endpoint.
feedAuthHeaderstringA string containing the authentication header for the endpoint.
schedulePathstringA string containing the path to the endpoint.

Configuration​

Configuration is an object that defines the basic behavior of a widget and allows enabling or disabling widget features that cannot be configured within the widget's user interface.

Type​

interface SimpleChartWidgetConfig {
  symbolSearchTypes?: SimpleChartWidgetSymbolSearchType[],
  symbolSearchViewMode?: SymbolSearchViewMode,
  aggregationPeriodSelectorViewMode?: ToolbarSelectorViewMode,
  rangeSelectorViewMode?: ToolbarSelectorViewMode,
  seriesTypeSelectorViewMode?: ToolbarSelectorViewMode,
  dataExportEnabled?: boolean,
  delayNotificationEnabled?: boolean,
  symbolScheduleStatusEnabled?: boolean,
  timezone?: string,
  onlyTradingHoursCandles?: boolean,
  lastPriceLineEnabled?: boolean,
  lastPriceLabelEnabled?: boolean,
  crosshairSnap?: boolean,
  crosshairSnapCandles?: SimpleChartWidgetCrosshairSnapCandles,
  locale?: LocaleSettings,
}

Properties​

NameTypeDefaultDescription
symbolSearchTypes
Optional
SimpleChartWidgetSymbolSearchType[]
[
 'STOCK',
 'FOREX',
 'FUTURE',
 'OPTION',
 'ETF',
 'PRODUCT'
, 'INDEX'
, 'CFD'
]
A list of instrument types uses for symbols search.
symbolSearchViewMode
Optional
SymbolSearchViewMode
'available'
View mode of the symbol search in the toolbar.
aggregationPeriodSelectorViewMode
Optional
ToolbarSelectorViewMode
'available'
View mode of the aggregation period select in the toolbar.
rangeSelectorViewMode
Optional
ToolbarSelectorViewMode
'available'
View mode of the range select in the toolbar.
seriesTypeSelectorViewMode
Optional
ToolbarSelectorViewMode
'available'
View mode of the series type select in the toolbar.
dataExportEnabled
Optional
boolean
false
A flag that controls a visibility of an export button.
delayNotificationEnabled
Optional
boolean
false
A flag that controls a visibility of an data delay notification.
symbolScheduleStatusEnabled
Optional
boolean
false
A flag that controls a visibility of symbol schedule status in widget toolbar
timezone
Optional
string
client
environment
timezone
String corresponds to IANA Time Zone name used to display dates in spicified time zone
onlyTradingHoursCandles
Optional
boolean
false
A flag that controls if only trading hours candles are displayed
lastPriceLineEnabled
Optional
boolean
false
A flag that controls visibility of last price line in chart. Ignored for volume series.
lastPriceLabelEnabled
Optional
boolean
false
A flag that controls visibility of label for last price in chart. Ignored for volume series.
crosshairSnap
Optional
boolean
false
A flag that controls whether the crosshair should snap to the point or follow the pointer independent of points.
crosshairSnapCandles
Optional
SimpleChartWidgetCrosshairSnapCandles
'close'
Controls the snapping behavior of the crosshair specifically for candlestick charts. The value has no effect if crosshairSnap is set to false.
locale
Optional
LocaleSettings
{
  language: 'en',
  dateLocale: 'en-GB',
  numberLocale: 'en-GB'
}
An object that defines the language and regional settings of the widget.

State​

State is an object that represents the state of the widget.

Type​

interface SimpleChartWidgetState {
  symbol?: string,
  aggregationPeriod: SimpleChartPeriod,
  range: SimpleChartRange,
  seriesType: SimpleChartSeriesType,
}

Properties​

NameTypeDefaultDescription
symbol
Optional
string
undefined
A string containing the symbol by which the widget will display data.
aggregationPeriodSimpleChartPeriod
'15m'
A string value defining aggregation period.
rangeSimpleChartRange
'1D'
A string value defining chart range.
seriesTypeSimpleChartSeriesType
'line'
Type of the chart.

Type Reference​

Slot​

Type​

'header'

SimpleChartPeriod​

Type​

'1m' | '3m' | '5m' | '10m' | '15m' | '30m' | '45m' | '1H' | '2H' | '4H' | '1D' | '1W' | '1M'

SimpleChartRange​

Type​

'1D' | '1W' | '1M' | '6M' | 'YtD' | '1Y' | '5Y' | 'All'

SimpleChartSeriesType​

Type​

'candlestick' | 'line' | 'mountain' | 'volume' | 'baseLine'

SimpleChartWidgetSymbolSearchType​

Type​

'STOCK' | 'FOREX' | 'FUTURE' | 'OPTION' | 'ETF' | 'PRODUCT' | 'INDEX' | 'CFD'

SymbolSearchViewMode​

Type​

'available' | 'hidden' | 'value-only'

ToolbarSelectorViewMode​

Type​

'available' | 'hidden'

SimpleChartWidgetCrosshairSnapCandles​

Type​

'high' | 'low' | 'open' | 'close'

LocaleSettings​

An object that defines the language and regional settings of the widget.

Type​

{
  language: Language,
  dateLocale: string,
  numberLocale: string,
}

Language​

Type​

'en' | 'de' | 'ar'