Documentation / Charts
CandlestickChart
Open, high, low, close: one candle per session. It is the only chart of the kit painted with the status pair (--color-chart-up / --color-chart-down) rather than the palette: a rise and a fall are two directions of one measure, not two identities.
Green against red is the worst pair there is under colour vision deficiency; the direction is therefore carried a second time by the shape: hollow body on a rise, filled on a fall. fillRising fills both, at the cost of that redundancy — keep it for contexts where colour is enough. The value axis is not anchored at zero: a price is read within its window.
Client component ("use client") with a tooltip, keyboard parity and an accessible data table (tableView).
Examples
Two weeks of sessions
Four props name the open, high, low and close fields of each row.
import { CandlestickChart } from "@synertech/ui";
const sessions = [
{ day: "2 mars", open: 182.4, high: 189.1, low: 180.2, close: 187.6 },
{ day: "3 mars", open: 187.6, high: 191.4, low: 183.0, close: 184.2 },
{ day: "4 mars", open: 184.2, high: 186.7, low: 176.4, close: 178.1 },
{ day: "5 mars", open: 178.1, high: 194.2, low: 177.5, close: 192.8 },
{ day: "6 mars", open: 192.8, high: 196.0, low: 190.1, close: 191.2 },
{ day: "9 mars", open: 191.2, high: 193.4, low: 185.6, close: 186.0 },
{ day: "10 mars", open: 186.0, high: 188.2, low: 181.9, close: 187.9 },
{ day: "11 mars", open: 187.9, high: 199.4, low: 187.1, close: 198.6 },
{ day: "12 mars", open: 198.6, high: 201.2, low: 194.8, close: 195.4 },
{ day: "13 mars", open: 195.4, high: 197.1, low: 188.0, close: 189.3 },
];
export function Basic() {
return (
<CandlestickChart
data={sessions}
x={{ key: "day" }}
open="open"
high="high"
low="low"
close="close"
y={{ label: "Cours (€)" }}
title="Cours de l’action"
description="Corps creux à la hausse, plein à la baisse"
/>
);
}Threshold and French labels
referenceLines draws a cost price; openLabel, closeLabel, riseLabel… rename the entries of the tooltip, the legend and the table.
import { CandlestickChart } from "@synertech/ui";
const sessions = [
{ day: "2 mars", open: 182.4, high: 189.1, low: 180.2, close: 187.6 },
{ day: "3 mars", open: 187.6, high: 191.4, low: 183.0, close: 184.2 },
{ day: "4 mars", open: 184.2, high: 186.7, low: 176.4, close: 178.1 },
{ day: "5 mars", open: 178.1, high: 194.2, low: 177.5, close: 192.8 },
{ day: "6 mars", open: 192.8, high: 196.0, low: 190.1, close: 191.2 },
{ day: "9 mars", open: 191.2, high: 193.4, low: 185.6, close: 186.0 },
{ day: "10 mars", open: 186.0, high: 188.2, low: 181.9, close: 187.9 },
{ day: "11 mars", open: 187.9, high: 199.4, low: 187.1, close: 198.6 },
{ day: "12 mars", open: 198.6, high: 201.2, low: 194.8, close: 195.4 },
{ day: "13 mars", open: 195.4, high: 197.1, low: 188.0, close: 189.3 },
];
const euros = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });
export function WithReference() {
return (
<CandlestickChart
data={sessions}
x={{ key: "day" }}
open="open"
high="high"
low="low"
close="close"
format={(value) => euros.format(value)}
referenceLines={[{ value: 190, label: "Prix de revient" }]}
openLabel="Ouverture"
highLabel="Plus haut"
lowLabel="Plus bas"
closeLabel="Clôture"
riseLabel="Hausse"
fallLabel="Baisse"
title="Cours de l’action"
/>
);
}Filled bodies and brand colours
fillRising also fills the rising sessions; colors replaces the status pair. The shape then no longer carries the direction: colour alone states it.
import { CandlestickChart } from "@synertech/ui";
const sessions = [
{ day: "2 mars", open: 182.4, high: 189.1, low: 180.2, close: 187.6 },
{ day: "3 mars", open: 187.6, high: 191.4, low: 183.0, close: 184.2 },
{ day: "4 mars", open: 184.2, high: 186.7, low: 176.4, close: 178.1 },
{ day: "5 mars", open: 178.1, high: 194.2, low: 177.5, close: 192.8 },
{ day: "6 mars", open: 192.8, high: 196.0, low: 190.1, close: 191.2 },
{ day: "9 mars", open: 191.2, high: 193.4, low: 185.6, close: 186.0 },
{ day: "10 mars", open: 186.0, high: 188.2, low: 181.9, close: 187.9 },
{ day: "11 mars", open: 187.9, high: 199.4, low: 187.1, close: 198.6 },
{ day: "12 mars", open: 198.6, high: 201.2, low: 194.8, close: 195.4 },
{ day: "13 mars", open: 195.4, high: 197.1, low: 188.0, close: 189.3 },
];
export function FilledCustomColors() {
return (
<CandlestickChart
data={sessions}
x={{ key: "day" }}
open="open"
high="high"
low="low"
close="close"
fillRising
colors={{ up: "#0f766e", down: "#b45309" }}
height={260}
title="Cours de l’action"
/>
);
}Session detail
onCandleClick receives the session with its change (change) and its direction (rising).
import { useState } from "react";
import { CandlestickChart, type Candle } from "@synertech/ui";
const sessions = [
{ day: "2 mars", open: 182.4, high: 189.1, low: 180.2, close: 187.6 },
{ day: "3 mars", open: 187.6, high: 191.4, low: 183.0, close: 184.2 },
{ day: "4 mars", open: 184.2, high: 186.7, low: 176.4, close: 178.1 },
{ day: "5 mars", open: 178.1, high: 194.2, low: 177.5, close: 192.8 },
{ day: "6 mars", open: 192.8, high: 196.0, low: 190.1, close: 191.2 },
{ day: "9 mars", open: 191.2, high: 193.4, low: 185.6, close: 186.0 },
{ day: "10 mars", open: 186.0, high: 188.2, low: 181.9, close: 187.9 },
{ day: "11 mars", open: 187.9, high: 199.4, low: 187.1, close: 198.6 },
{ day: "12 mars", open: 198.6, high: 201.2, low: 194.8, close: 195.4 },
{ day: "13 mars", open: 195.4, high: 197.1, low: 188.0, close: 189.3 },
];
const euros = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR" });
export function SessionDetail() {
const [candle, setCandle] = useState<Candle | null>(null);
return (
<div className="flex flex-col gap-3">
<CandlestickChart
data={sessions}
x={{ key: "day" }}
open="open"
high="high"
low="low"
close="close"
format={(value) => euros.format(value)}
tableView="toggle"
title="Séances de mars"
onCandleClick={setCandle}
/>
{candle && candle.change !== null ? (
<p className="text-sm text-gray-600 dark:text-gray-300">
{candle.label} : {candle.rising ? "hausse" : "baisse"} de{" "}
{euros.format(Math.abs(candle.change))}
</p>
) : null}
</div>
);
}API reference
Components
Open, high, low and close, one mark per session.
A narrow audience, and no other shape of the kit can stand in for it: four figures per position, of which two are a range and two are an ordered pair inside it. A line of closing prices throws away three quarters of that.
The colours are the status pair, not the categorical palette: a rise and a fall are not two identities a reader has to tell apart, they are the same measurement pointing two ways. Green against red is also the worst pair there is under colour vision deficiency, so the direction is carried a second time by the shape of the body — hollow for a rise, filled for a fall. Colour alone never says which way a session went.
The value axis does not anchor at zero. A price is read for its level and its movement; a share worth 180 dollars read from zero is a flat band at the top of the plot.
import { CandlestickChart } from "@synertech/ui";Props — CandlestickChartProps
| Prop | Type | Default | Description |
|---|---|---|---|
close• |
string |
— | Field holding the closing figure. |
data• |
ChartDatum[] |
— | One row per session. |
high• |
string |
— | Field holding the highest figure reached. |
low• |
string |
— | Field holding the lowest figure reached. |
open• |
string |
— | Field holding the opening figure. |
x• |
ChartXAxisConfig |
— | Field holding the session's label — usually a date. |
actions |
ReactNode |
— | Slot on the right of the caption: an export button, a range picker. A filter that frames several panels belongs in a |
candleSize |
number |
— | Caps the thickness of a body. |
closeLabel |
string |
— | |
colors |
{ up?: string; down?: string } |
— | Replaces the two status colours. Any CSS colours. |
description |
ReactNode |
— | |
emptyState |
ReactNode |
— | Replaces the "no data" state: usually an |
error |
boolean |
false |
The data could not be loaded. Never the same thing as having none: a panel that says "no data" after a failed request states something false, and offers no way out. |
errorState |
ReactNode |
— | Replaces the whole built-in error state, message and button included. |
fallLabel |
string |
— | |
fillRising |
boolean |
false |
Fills the body of a rising session instead of leaving it hollow. Off by default, and that default is an accessibility decision rather than a stylistic one: hollow against filled is what carries the direction for a reader who cannot separate green from red, which is the single worst pair there is under colour vision deficiency. |
format |
(value: number) => string |
— | |
grid |
ChartGridLines |
"y" |
|
height |
number |
300 |
|
highLabel |
string |
— | |
legend |
boolean | ChartLegendPosition |
— | |
loading |
boolean |
false |
Dims the plot while fresh data loads; a first load shows a spinner. |
locale |
string |
— | BCP 47 tag the numbers and the dates are written in. Defaults to the |
lowLabel |
string |
— | |
margin |
Partial<ChartMargin> |
— | |
onCandleClick |
(candle: Candle) => void |
— | Called with the mark that was clicked. Enter and Space on the focused chart do the same for the mark the keyboard is on. |
onRetry |
() => void |
— | Draws the retry button in the error state, and is called when pressed. |
openLabel |
string |
— | |
plotLabel |
string |
— | |
referenceLines |
ChartReferenceLine[] |
— | |
riseLabel |
string |
— | |
size |
ChartSize |
"md" |
|
tableView |
boolean | "toggle" |
false |
|
title |
ReactNode |
— | |
tooltip |
boolean | ((candle: Candle) => ReactNode) |
true |
|
width |
number |
— | |
y |
ChartYAxisConfig |
— |
+ 277 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).
Types
Candle
InterfaceOne session, as the tooltip and the click handler see it.
interface Candle| Field | Type | Default | Description |
|---|---|---|---|
change• |
number | null |
— |
|
close• |
number | null |
— | |
datum• |
ChartDatum |
— | |
high• |
number | null |
— | |
index• |
number |
— | |
label• |
string |
— | |
low• |
number | null |
— | |
open• |
number | null |
— | |
rising• |
boolean |
— |
|
x• |
ChartXValue |
— |