Esta página ainda não foi traduzida, por isso aparece em inglês.
Styling the widget
The widget's look is a set of tokens: the corners of each kind of part, control and bar sizes, type, borders,
shadows, how a chosen button shows, and whether the toolbar and drawing tools sit along the edges or float.
Start from a preset and change what you like. Colours stay with the theme (dark / light,
see the API); a look works with either. Graphite, the default, and Modern each
bring a dark and a light of their own; the other looks share the colours that were the widget's before them.
Presets
| Preset | Look |
|---|---|
graphite (default) | A trading desk's chrome with no hue of its own: grounds a shade apart (#131416 / #ffffff) with hairlines between. Few sizes on purpose: controls 20, 24, 28, 36 or 40 px tall,
every corner 3 px, one shadow for what floats and none elsewhere. What is picked (an interval, a tool, a tab)
shows on a lighter ground in the text's own colour; amber is kept for what you act on. Switches are boxes
that are ticked, and the account table's columns are as wide as their figures. Its face is IBM Plex Sans
where your page loads it, the system's own otherwise. On the chart, without a theme object of yours, its
colours are GRAPHITE_DARK_THEME and GRAPHITE_LIGHT_THEME. |
modern | A code editor's window, in its Dark Modern and Light Modern colours. The chart on the editor's ground
(#1f1f1f / #ffffff) with the bars around it a shade off it and hairlines between;
16 px icons in 28 px buttons on a 38 px toolbar; 4 px controls, 6 px menus and 8 px dialogs. The logo's amber
(#e8961e) only for what you act on and what you picked, with dark ink on it, and a deeper or
lighter amber for links and focus. Candles in teal
(#089981) and red (#f23645), shaded deeper or lighter where they are text, so a
change reads at 5:1 or more. Its face is Geist where your page loads it, the system's own otherwise; its
figures are Print's. On the chart, without a theme object of yours, its colours are MODERN_DARK_THEME and MODERN_LIGHT_THEME, which a chart of your own can take too.
A chosen button and tool are the accent's fill (--tcw-accent-fill) with its ink, so a page that sets
the accent tokens sets those too. |
print | The default before Modern and Graphite, colours and all. Paper and ink. An off-white and an off-black ground, grey for everything that is normal and colour only where it means something; hairlines, 3 px controls, 5 px menus and 8 px dialogs; large icons drawn in fine lines; labels as written and a medium weight for emphasis; the system's own face (Segoe UI Variable on Windows 11); every figure, on the chart too, in a sans face whose digits are one width (Segoe UI on Windows, Helvetica Neue on Apple systems, Roboto on Android), so prices line up in columns. A chosen button is solid ink, a chosen tool ink blue. |
studio | Rounded 7 px controls, 11 px menus and 16 px dialogs. Groups are spaced instead of ruled, menus float on soft shadows, the interval buttons sit in a segmented track, and a chosen button is a tinted fill. |
terminal | Dense and square: 2 px corners, 26 px controls, rules between groups, capital labels, and a line under the chosen button. Price tags on the chart are square. |
capsule | Pills everywhere, pill price tags included. The toolbar and the drawing tools float as islands, menus are frosted glass, and a chosen button is a solid pill. |
desk | A desktop trading platform's window: Tahoma at 12 px for the labels and the chart's figures alike, square corners and price tags, bars a step tighter (24 px controls), rules between groups, and a tinted chosen button. Where there is no Tahoma it falls back to Verdana, Segoe UI or DejaVu Sans. |
Picking a look
import { ChartWidget, ChartWidgetGrid } from '@tradecanvas/chart/widget'
const widget = new ChartWidget(host, { ui: 'terminal' })
widget.setUI('capsule') // in place: nothing is rebuilt
widget.getUI() // every token, resolved
// A grid: every chart and the grid's bar, and the charts it adds later
const grid = new ChartWidgetGrid(host, { layout: '2x2', widget: { ui: 'terminal' } })
grid.setUI('studio')
grid.getUI() Density
The chart and the widget open with room around what they draw. A candle's body is the slot × φ⁻¹ (62%) at every
zoom, the rest a gap, and the chart opens at φ⁴ ≈ 6.85 px a slot (barLayout: 'golden'), about 250
bars across a 1920 px screen. The newest bar rests 8 slots from the price axis. The prices keep φ⁻⁴·⁵ (11.5%)
of the plot's height free above the highest high and below the lowest low; with volume on, the volume band is
under the candles with a gap of φ⁻⁶ (5.6%) between, so the two never overlap. The legend stands 12 px in from the
plot's corner. In the widget every size and gap is an even number of pixels, and buttons, bars and menu rows
have 12 px beside their text.
density sets all of it at once, for the widget in ui and for a chart of your own in its
options:
ui.density | The widget | Its chart |
|---|---|---|
'comfortable' | The default: even sizes (in Modern a 28 px button and a 16 px icon, in Print 34 and 20), spacing 2 · 4 · 6 · 8 · 12 · 20 · 32, 12 px of padding in a control. | Comfortable, golden bars. |
'classic' | The look's sizes on the spacing before 2.0: 2 · 3 · 5 · 8 · 13 · 21 · 34, 8 px of padding in a control. With Print ({ preset: 'print', density: 'classic' }) the widget as it was before 2.0 (at a screen scale of 100% the same pixels, but for the price axis's tick marks, which are sharper), a 33 px button. | Compact, with the golden bars the widget had. |
'compact' | Smaller controls (in Modern a 24 px button, in Print 26, a 16 px icon) on the classic spacing. | Compact, classic bars. |
'spacious' | Bigger controls (in Modern a 34 px button and a 20 px icon, in Print 42 and 26). | Comfortable, golden bars. |
'airy' | Spacious, with the figures on the axes and in the legend in the look's sans face. | Comfortable, golden bars. |
A chart's density | Bars | Room past the newest bar | Above and below the prices | Over the volume band | Legend from the corner |
|---|---|---|---|---|---|
'comfortable' (default) | golden | 8 slots | φ⁻⁴·⁵ (11.5%) | φ⁻⁶ (5.6%) | 12 px in, 8 px down |
'compact' (as before 2.0) | classic: a 2 px gap, 10 px a slot to open | 5 slots | φ⁻⁵ (9%) | φ⁻⁷ (3.4%) | 8 px in, 6 px down |
// The widget as it was before 2.0
new ChartWidget(host, { ui: { preset: 'print', density: 'classic' } })
widget.setUI({ preset: 'print', density: 'classic' })
// A chart of your own as it was before 2.0
import { Chart, CHART_SPACING, MONO_FONT_FAMILY } from '@tradecanvas/chart'
const chart = new Chart(host, { density: 'compact', font: { family: MONO_FONT_FAMILY } })
chart.setDensity('comfortable') // and back
chart.getDensity() // 'comfortable'
CHART_SPACING.comfortable // the numbers each density sets
// One part of it
new Chart(host, { barLayout: 'classic' }) // a 2 px gap between bars, the rest comfortable
new Chart(host, { rightMargin: 5 }) // 5 slots past the newest bar
chart.setBarLayout('golden')
chart.setFont({ family: MONO_FONT_FAMILY, sizeSmall: 12 }) // the axes' and tags' face and size
chart.setFont(null) // the theme's own font again The barLayout and rightMargin a chart is made with stay through a change of density.
In the widget, chartOptions.density, chartOptions.barLayout and a family in chartOptions.font win over the look's; sizes alone in chartOptions.font keep the look's
face. Over bars on screen a new layout keeps the zoom and only splits each slot again.
On whole pixels
At a screen scale of 125% or 150% a CSS pixel is 1.25 or 1.5 device pixels, and a line drawn 1 px wide between two of them goes soft. The chart sizes its canvases by the browser's own count of device pixels and puts its hairlines on them: the grid, the axes' lines and ticks, the crosshair, the last price's line, order, alert and level lines, wicks, a pane's divider and the edges of price tags. A 1 px line is one device pixel wide at 125% and at 150%, as the browser draws a 1 px border. In the widget, sizes are even so that an icon sits a whole number of pixels from its button's edge and a button from its bar's, and the toolbar's text buttons are a whole number of pixels wide where the browser can round a box sized by its content (Chrome and Edge 129 and later), so the icons after them stay sharp too.
The golden ratio
Print keeps its proportions to the golden ratio, φ ≈ 1.618, so sizes that sit together relate the same way everywhere:
| What | Rule | Values (px) |
|---|---|---|
| Sizes | Half steps of φ, each the even number nearest its step (20.4, 25.9, 32.9, 41.9): an icon, its small button, its button, the bar, and the drawing tools' column on the bar's step; a menu row is as tall as a button. The button departs from the rule: 32 is nearer its step, and it is 34, the size the 33 of 1.x read as, which leaves a 20 px icon 7 px a side. The drawing tools' icons are a half step over the others' (26 against 20), their buttons a little short of it, to keep 3 px either side in the column. | 20 · 26 · 34 · 42 |
| Spacing | Fibonacci numbers on a 4 px grid (1, 2, 3, 5, 8 times 4), with 2 and 6, the halves of 4 and 12, under them. From 8 up neighbours stand at 1.5, 1.67 and 1.6, near φ; the small steps climb by 2 px, where a ratio of φ has no even numbers to land on. The classic and compact densities keep the plain Fibonacci numbers, 2 · 3 · 5 · 8 · 13 · 21 · 34. | 2 · 4 · 6 · 8 · 12 · 20 · 32 |
| Corners | Fibonacci numbers. A nested corner is the one around it less the padding between, so the curves run parallel: a menu's 5 is its rows' 1 and its 4 of padding. | 1 · 2 · 3 · 5 · 8 |
| Type | Steps of the cube root of φ, so every third size is φ larger: a dialog's title is φ times its text. Never under 10 px, where letters with two marks (Vietnamese ế, ộ) stop reading. | 10 · 11 · 13 · 15 · 18 · 21 |
The type steps follow the body size you set (font.size); a line of body text is an even height
(18 px at 13 px). density moves the sizes a half step down or up. PHI, FIBONACCI, phiStep(base, steps, perPhi) and evenPx(n) come from @tradecanvas/commons for a look of your own.
On wide screens
The widget draws its bars, buttons, icons and type bigger as it widens, so a 4K screen is not all small print:
as set up to full HD, then a sixth of φ bigger from 1800 px wide, a third from 2560 (4K at 150%) and a half from
3400 (4K at 100%), each size to the even number nearest. The chart's axis type grows with it. ui.scale sets a scale of your own at every
width; 1 keeps the sizes as they are.
Your own look
A theme starts from a preset (Graphite when you name none) and changes what it names. Corners set on the scale reach every part that follows it, unless you set that part's own.
widget.setUI({
preset: 'studio',
radius: { xs: 3, sm: 5, md: 10, lg: 12, xl: 18 }, // the scale, px (999: pills)
components: { dialog: 20, tag: 0 }, // a part's own corners
density: 'compact', // compact · classic · comfortable · spacious · airy
sizes: { toolbar: 40 }, // px; wins over density
scale: 'auto', // or a number; 'auto' grows with the widget's width
font: {
family: "'Manrope', system-ui, sans-serif",
mono: "'JetBrains Mono', monospace",
size: 13, smallSize: 12, // body; figures in tables, field names (set, nothing to read is smaller)
weight: 500, strongWeight: 600,
labelCase: 'uppercase', labelTracking: 0.06, // small labels
},
borders: { width: 1, separators: true }, // rules between toolbar groups
shadows: { menu: '0 12px 30px rgba(0, 0, 0, 0.4)' },
blur: 12, // frosted floating surfaces, px
active: 'solid', // tint · solid · underline
toolbar: 'floating', // docked · floating
sidebar: 'floating',
intervals: 'segmented', // plain · segmented
tagRadius: 999, // the chart's price tags and pills
iconStroke: 1, // icon lines, CSS px at every size (0: as drawn)
}) | Field | What it sets |
|---|---|
radius | The corner scale xs, sm, md, lg, xl, px (0–999). |
components | A part's own corners: control (buttons), input, menu, dialog, panel (alerts, data window, order ticket), tooltip, tag, toast, toolbar and sidebar (their own box, seen when they float). By default controls and
fields take md, menus and panels lg, dialogs xl, tooltips and tags sm. |
density / sizes | toolbar height, control and controlSmall heights, icon, sidebar width and menuItem height, px. compact and spacious are a look's smaller and bigger sizes (Print's a half step of φ down or up), and classic its sizes on the spacing before 2.0 (see Density, which also sets the spacing and the chart's room). The drawing tools' buttons and icons are a
half step of φ over control and icon (the same size in compact). They keep
room either side in the sidebar column, and where the column is too short for them all they shrink,
down to the icon size and 2 px a side, before it scrolls. |
font | Families (CSS lists), body size (11–20 px; the other sizes follow it a third of φ apart), weights,
and the case and letter spacing (em) of small labels such as section titles. |
borders | Border width, and whether rules separate the toolbar's groups and the drawing tools. |
shadows | CSS shadows of menus, dialogs and tooltips. |
blur | Frosted menus, px: above 0, menus let some of the chart through, blurred. |
active | How a chosen button shows: a tinted fill, a solid pill, or an underline. |
toolbar / sidebar | Along the edge, or floating as an island. |
intervals | The interval buttons as they are, or in a segmented track. |
tagRadius | Corners of the price tags, axis pills and order badges the chart draws. |
iconStroke | The icons' lines, CSS px from 0.5 to 3, the same width at every icon size (at most 1 px on icons under 14 px). 0 draws them as the
icon set does, thicker as the icon grows. Modern's are 1.5 and Print's 1; the other looks draw them as they are. |
Values it can't use (out of range, or CSS that could leave its declaration) are ignored and keep the preset's.
Fonts
The widget loads no fonts: it names them, and the browser falls back along each list. Modern names Geist, then Print's faces, so it needs nothing loaded either. Print names the faces every system has: Segoe UI, San Francisco or Roboto for labels, and for figures Segoe UI, Roboto, Helvetica Neue or Arial, whose digits are all one width, so it needs nothing loaded; Desk names Tahoma, then Verdana, which also come with the system. Studio names Manrope, then Inter; Terminal IBM Plex Sans Condensed and IBM Plex Mono; Capsule Sora. Load the ones you want:
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap"> CSS variables
The tokens are CSS variables on the widget's root (and on its dialogs). Without the ui option they
stay the stylesheet's — Graphite's — so your own CSS can set them: the widget puts its stylesheet first in the
page, so a rule of yours on .tcw-root wins. With ui, the widget writes them on the
element, and they win.
.tcw-root {
--tcw-radius: 4px; /* the md corner: buttons and fields follow it */
--tcw-dialog-radius: 12px;
--tcw-control-h: 28px;
--tcw-font: 'Inter', system-ui, sans-serif;
} | Variables | From |
|---|---|
--tcw-radius-xs, -sm, --tcw-radius, -lg, -xl | radius |
--tcw-control-radius, --tcw-input-radius, --tcw-menu-radius, --tcw-dialog-radius, --tcw-panel-radius, --tcw-tooltip-radius, --tcw-tag-radius, --tcw-toast-radius, --tcw-toolbar-radius, --tcw-sidebar-radius | components |
--tcw-toolbar-h, --tcw-control-h, --tcw-control-h-sm, --tcw-icon, --tcw-sidebar-w, --tcw-menu-item-h | sizes |
--tcw-font, --tcw-font-mono, --tcw-font-size (and -xs, -sm, -lg, -xl, -display), --tcw-weight, --tcw-weight-strong, --tcw-label-case, --tcw-label-tracking | font |
--tcw-border-w, --tcw-sep-w | borders |
--tcw-menu-shadow, --tcw-dialog-shadow, --tcw-tooltip-shadow | shadows |
--tcw-blur, --tcw-surface-opacity | blur |
--tcw-space-1 … --tcw-space-7 | density: spacing, 2 to 32 px (2 to 34 in classic and compact) |
--tcw-control-pad, --tcw-bar-pad, --tcw-menu-row-pad | density: the room beside a button's label, a bar's first button and a menu row's text |
--tcw-line-height, --tcw-line-xs, --tcw-legend-line, --tcw-legend-line-pane | density: a line of body text, of the smallest type, and of an indicator's row on the chart and in a pane |
--tcw-text-w | density: the bars' text buttons a whole number of pixels wide (auto: as wide as their text) |
--tcw-kind-1 … --tcw-kind-5 | The stylesheet: the symbol search’s colours for the kinds of symbol (stock, futures, index, crypto, forex), set for the dark and the light theme. Set them in a palette of your own, or the badges keep these hues. |
--tcw-font-features | The stylesheet: normal, the faces as drawn. The ui option never sets it, so a rule of yours on .tcw-root turns on your face's OpenType features (Inter's one-storey a and open digits: 'cv11', 'ss01'). They reach the widget's text, its buttons and fields too; the chart's text (its canvases and its tooltips) never takes them. |
The layout switches are data attributes on the same elements, for CSS of your own: data-tcw-ui (the preset), data-tcw-active, data-tcw-toolbar, data-tcw-sidebar, data-tcw-intervals and data-tcw-separators (on / off).
Fields, lists and the calendar
Every field in the widget (alerts, settings, the order ticket, go to date, an indicator's inputs) has one look: a faint fill and a hairline, a firmer line on hover, and on focus the line takes the accent, with no ring around it. A select opens the widget's own list, with a check on the chosen row, groups as headings, the arrow keys, Enter, Escape and typing a letter; a date field opens the widget's calendar, weeks from the day the language starts them, today underlined, days outside a field's min and max greyed out. Checkboxes, radios, sliders and switches follow the same tokens, and so do the scrollbars: thin and rounded, a thumb on no track.
The fields stay the browser's own <select> and <input>: values, events and forms work as before, and on a touch screen the phone's own wheel and calendar open, which suit a thumb better.
The look comes from these variables, set for the dark and the light theme:
--tcw-field-bg, --tcw-field-bg-hover, --tcw-field-bg-focus, --tcw-field-line, --tcw-field-line-hover, --tcw-field-line-focus, --tcw-field-placeholder, --tcw-check-line, --tcw-scroll-thumb, --tcw-scroll-thumb-hover.
.tcw-root {
--tcw-field-bg: transparent; /* fields as lines, no fill */
--tcw-field-line: rgba(255, 255, 255, 0.12);
--tcw-field-line-focus: #5b8cff; /* focus in your brand colour */
} The chart's look: style overrides
The theme sets the chart's colours as a whole. Any one part of what the chart draws can be set apart from it, by key: the grid's lines each way, the crosshair, the axes, the panes, the legend, the last price, the volume, the session breaks and the main series as each chart type draws it. A key left alone follows the theme, so a theme switch still recolours everything you didn't set.
import { Chart } from '@tradecanvas/chart'
const chart = new Chart(host, {
overrides: { 'grid.vertical.visible': false }, // to start with
})
chart.applyOverrides({
'series.candlestick.upColor': '#26a69a', // every up/down type falls back to it
'series.candlestick.downColor': '#ef5350',
'grid.horizontal.style': 'dotted',
'crosshair.vertical.style': 'solid',
'crosshair.labelBackground': '#2962ff',
'lastPrice.style': 'solid',
'panes.background': '#0d1117',
'legend.textColor': '#c9d1d9',
})
chart.applyOverrides({ 'legend.textColor': null }) // null takes a key away
chart.resetOverrides(['grid.horizontal.style']) // or name the keys
chart.setOverrides({ 'background.color': '#000' }) // all of a layer at once
chart.getStyleValue('series.bar.upColor') // '#26a69a': what a key resolves to
chart.getStyle().grid.vertical // { visible: false, color, style, width }
chart.on('styleChange', (e) => e.payload.layer) // 'host' or 'user' Keys
| Keys | What they set |
|---|---|
background.color | The chart's background (and the panes', unless they have their own). |
panes.background, .separatorColor, .titleColor | Indicator panes: background, the bar at their top, their name. |
grid.horizontal.*, grid.vertical.* | visible, color, style (solid · dashed · dotted), width — each way apart. |
grid.vertical.periodsOnly | true rules the vertical grid where a period begins, not at the time axis's labels: at each day's first bar on an intraday chart, each month's on a chart of days, each year's on a chart of weeks or months, in the zone the axis shows. Where those would be closer than 40 px (a chart of days zoomed out to years) the next coarser period is ruled, and no line is drawn where no such period begins on view. It needs the time axis: with that switched off the lines are as without the key. |
crosshair.horizontal.*, crosshair.vertical.* | The same four for the crosshair's lines (solid hairlines by default). |
crosshair.labelBackground, .labelTextColor | The price and time pills on the axes, and on the panes' scales. |
axis.price.lineColor, .textColor, axis.time.* | Each axis's line and labels (the panes' scales take the price axis's). |
lastPrice.limitColors | true draws the last price's line and tag in a day's limit's colour while the price is at that limit: the ceiling's at or over the ceiling, the floor's at or under the floor, the reference's at the reference price. Between them, and with no limits known, they keep the day's colour. At a limit its colour is over lastPrice.labelBackground, and the legend keeps the day's colours; the limit's own tag gives way to the last price's while the two would lie against each other. For a market with a day's limits whose boards colour prices by them; off unless you set it. |
crosshair.labelChange | true writes, under the price the crosshair names on the price axis, how far that price is from the last one, in percent (+1.25%), in the chart's locale. None is written with no last price, with the last price hidden, or on a scale that is in percent or indexed already. The axis is given room for it. The Graphite themes have it on (a theme's own crosshairChange); the others off. |
axis.price.valueTagsOutlined | true draws an indicator's value tags on the price axis outlined (the chart's background, or a pane's own, inside an edge of the line's colour, its text in that colour) instead of filled with the line's colour: in the price pane, the indicator panes and on the left scale. A line too close to the background to be read on it has its value written in a deeper shade of its own colour, until it reads at 4.5:1. The Graphite themes draw them outlined unless this is false. The bid's, the ask's and the high's and low's tags, and an order's and a position's, are outlined with them. |
legend.textColor, .labelColor | The legend's values, and its labels (O, H, L, Vol). |
legend.upColor, .downColor | A rise and a fall where a bar's values are read: the legend's close and change, the crosshair and pinned tooltips, the measure tool. They follow the series' unless set, so a chart that hides its candles (an overlay drawing its own) sets these and keeps them. |
lastPrice.visible, .upColor, .downColor, .style, .width | The last-price line and tag; their colours follow the series' unless set. The time left in the bar (features.barCountdown) hangs under the tag. |
lastPrice.labelBackground, .labelTextColor | The last price's tag in one colour whatever the day's direction, and its text. Unset, the tag is the up or the down colour and its text the one that reads on it; the line keeps upColor and downColor either way. The countdown under the tag takes both. |
volume.upColor, .downColor | The volume bars. |
sessionBreaks.color, .style, .width | The day, week and month breaks. |
highLow.color, watermark.color | The high and low lines, the watermark. |
trading.buyColor, .sellColor, .profitColor, .lossColor, .entryColor | Orders (buy, sell) and positions (profit, loss, entry), on the chart and on the price axis, over the trading config's colours. |
markers.longColor, .shortColor, .neutralColor | Signal markers, over their own style. |
tradeZones.profitColor, .lossColor, .activeColor | Trade zones: won, lost and still open. |
drawings.handleColor | A selected drawing's handles (white without it). |
series.<type>.* | The main series while it is drawn as that type: upColor, downColor, wickUpColor, wickDownColor (candles, Heikin-Ashi, volume candles, equivolume), color / lineColor and lineWidth (line, step line, line with markers, area, HLC area, baseline), topColor and bottomColor (area, HLC area). |
CHART_STYLE_KEYS lists every key with the kind of value it takes, and TypeScript checks keys and
values as you write them. Up and down colours fall back to series.candlestick.*, line colours and widths
to series.line.*, area fills to series.area.*, then to the theme; a wick takes its body's
colour once that is set. Unknown keys and values are left out with a warning.
Your app's and the user's
Overrides come in two layers. Yours (layer: 'host', the default) stay through theme switches and are
never saved. The user's (layer: 'user') win over yours, are kept with the theme they were made on —
colours picked on the dark theme come back with the dark theme — and are saved with saveState(). The
widget's Settings write the user's layer. Their tabs down the side set every part of the chart's look by these
keys: Symbol (the chart type on view, the last price, the volume), Status line, Scales, Appearance (background, grid, crosshair, session breaks), Layers and Trading (orders, positions, signal markers, trade zones). Every change
shows at once; Cancel puts them all back and OK keeps them as one undo step. The Template menu saves the look under a name, applies or deletes a saved one, and resets to the
theme's colours, whichever theme it is. A colour left to the part itself shows as Auto, and Auto takes one back there.
chart.applyOverrides({ 'background.color': '#0b0b0f' }, { layer: 'user' })
chart.getOverrides({ layer: 'user' }) // the user's, for the current theme
chart.getTheme() // the theme as set: the overrides go on it apart The grid and crosshair options (grid.hLineColor, crosshair.vLine.style…) are shorthand
for their keys. A grid of charts takes overrides for all of its charts: grid.applyOverrides(patch). The
React, Vue and Svelte components take them as an overrides prop.
Indicator plots and panes
// Each plot's own dash and visibility, by its key (colours and widths stay in colors / lineWidths)
chart.updateIndicatorStyle(macdId, { plots: { signal: { lineStyle: 'dashed' }, histogram: { visible: false } } })
// What every indicator of a kind starts with from now on
chart.setIndicatorDefaults('ema', { colors: ['#f5a623'], lineWidths: [2] })
// A pane's own background and separator, saved with its indicator
chart.setPaneStyle(rsiId, { background: '#101418', separator: '#f5a623' }) A hidden plot shows no value tag and no legend value. Every indicator leaves a hidden plot out, and nearly every one takes its plots' dash; a few that draw shapes of their own (Zig Zag, the volume profiles, the candle pattern marks) keep their own stroke. Lines an indicator dashes itself (Chandelier Exit, the pivot levels, Session VWAP's bands) stay dashed until their plot style says otherwise.
The chart's tags
The widget hands tagRadius to its chart (a shape in chartOptions.shapes stays until
you call setUI). On a bare Chart, set the shape yourself; it lasts across theme
switches. Price tags, axis and crosshair pills, order, position and bracket tags and period-level tags take it.
const chart = new Chart(host, { shapes: { tagRadius: 4 } })
chart.setShapes({ tagRadius: 999 }) // pill price tags, axis pills and order badges
chart.getShapes() The OHLCV legend
The legend at the top of the chart opens with a title line: the symbol, the interval and the exchange, then the bar under the pointer (the last bar otherwise) on the same line, open, high, low, close and the change. The volume follows on a line of its own. Where the plot is too narrow for the title line, as on a phone, it wraps, and the volume ends the last line when it fits there. The chart names the symbol and interval from its stream and the exchange from the symbol's details; setSymbolName('Bitcoin') names it yourself until the symbol changes, and showSymbol: false leaves the title out. Each value keeps its place while its digits change, so it doesn't jitter on live ticks. It can be turned off, or trimmed to the rows you want. In the widget it takes the look's figures face, at the size of the indicator rows listed under it; setUI sets that again, after a setLegend of your own.
new Chart(host, { features: { legend: false } }) // no legend at all
chart.setLegend({ visible: false }) // or at any time
chart.setLegend({
showSymbol: false, showOHLC: true, showChange: true, showVolume: false,
position: 'top-right',
fontSize: 11,
fontFamily: 'Inter, sans-serif', // null: the theme's font
ground: false, // no see-through ground under the rows
})
// The widget: no legend, and no switch for it in its Settings
new ChartWidget(host, { chartOptions: { features: { legend: false } } })
// Off to start, for the user to turn on in Settings
new ChartWidget(host).setSettings({ legendVisible: false }) Each row of the legend sits on a see-through ground of the chart's background, so lines drawn across the top of the plot (moving averages, a VWAP) run behind its text rather than through it. ground: false leaves it out. The widget's indicator rows under it have the same ground, the CSS variable --tcw-legend-ground (transparent for none).
The price scale and the volume band
The volume bars keep to a band along the bottom of the plot, φ^-4.5 (about 11.5%) of its height, and the fitted price scale keeps the candles above it, with a gap of φ^-7 (3%). Above the highest high it leaves φ^-5 (9%). With no volume on view (turned off, or bars that carry none) the candles take the band back. The scale also fits the overlay indicators and compare lines on view.
Volume colours
Volume bars take the theme's volumeUp and volumeDown (or the volume.* keys). The built-in themes draw them in one neutral ink, lighter under falling bars: the candles above already show which way the price went, so the bars stay a backdrop. They stay neutral when you or the widget's settings change the candle colours. For bars in the candles' colours, volumeColor(candleColor) gives a candle colour at the volume's opacity:
import { DARK_THEME, volumeColor } from '@tradecanvas/chart'
chart.setTheme({
...DARK_THEME,
candleUp: '#26a17b',
candleDown: '#e0525f',
volumeUp: volumeColor('#26a17b'),
volumeDown: volumeColor('#e0525f'),
})