CandleSeries
CandleSeries in UIToolbox is a series of a Graph that draws candles: the open, the high, the low and the close of a value in each period. Use it for the prices of a market in a trading game, the lowest and the highest score of each match day, the range of the temperature of each day, or any value that moves within a period.


Video tutorial: CandleSeries. All videos: Video tutorials.
<tb:Graph x-title="Day" y-title="Price">
<tb:CandleSeries
text="Grain"
candles="10, 14, 9, 13; 13, 15, 11, 12; 12, 16, 12, 15" />
<tb:GraphSeries text="Average" values="11, 12, 13" />
</tb:Graph>
<tb:Graph chart-type="Bar" y-title="Price" y2-title="Sold" y2-max="300">
<tb:GraphSeries
text="Sold"
values="40, 75, 60"
secondary-axis="true" />
<tb:CandleSeries
text="Iron"
max-items="30"
color="#3399FF"
down-color="#FF9933" />
</tb:Graph>
var graph = root.Q<Graph>("market");
var price = graph.Q<CandleSeries>();
// drops the oldest candle past MaxItems
price.AddCandle(day, new Candle(open, high, low, close));
// a list of candles, and the X of each
price.SetCandles(candles, days);
graph.DataPointSelected += (series, index) =>
{
if (series is CandleSeries candles)
Debug.Log(candles.GetCandle(index).Close);
};
The body of a candle goes from the open to the close: in the up color when the close is at or above the open, and in the down color when it is below. A thin wick goes from the low to the high. A candle is 60% as wide as the smallest X gap of the shown series, and the X range of the graph leaves half a gap on each side, so the first and the last candle show whole. The automatic Y range holds each candle from its low to its high.
Settings
| Setting (UXML) | Type | Default | Does |
|---|---|---|---|
candles |
string | "" | The candles: the open, the high, the low and the close of each candle with commas, and a ; or a new line between candles, as in 10, 14, 9, 13; 13, 15, 11, 12. X is the index. A high below the open or the close rises to the higher of them, and a low above them falls to the lower. A part that is not a number counts as 0. |
text |
string | "" | The name of the series, in the legend and the tooltips. |
color |
Color |
clear | The color of a rising candle and of the legend swatch. Clear takes --tb-graph-candle-up. |
down-color |
Color |
clear | The color of a falling candle. Clear takes --tb-graph-candle-down. |
max-items |
int | 0 | When above 0, AddCandle drops the oldest candles past this count. For live prices. |
hidden |
bool | false | Takes the candles out of the chart and the automatic ranges. The legend row stays, faded. |
secondary-axis |
bool | false | Plots the candles on the right Y axis, with its own range. |
The candles do not use line-width. values gives flat candles, as SetData does below.
Properties and methods
| Member | Description |
|---|---|
Candles, Label, Color, DownColor, MaxItems, Hidden, SecondaryAxis |
The settings above. |
CandleData |
The candles, for a binding. Setting it replaces them only when a candle differs, so a binding that sets equal candles each frame is free. Reading it gives the candles without a copy. |
GetCandle(index) |
The candle of the point at an index. |
SetCandles(candles, xs) |
Replaces the candles. X is the index, or the value at the same place of xs, which must have as many values. |
AddCandle(x, candle) |
Appends a candle at X, drops the oldest past MaxItems, and sends DataPointAdded with its close. |
Points, GetDataPoint(index) |
The points: the X and the close of each candle. |
DisplayColor, DisplayDownColor |
The colors the graph draws rising and falling candles with. |
Candle(open, high, low, close), Open, High, Low, Close, Rising |
A candle and its values. Rising is true when the close is at or above the open. |
Values, SetData and AddPoint give only a Y, so they give a flat candle at that Y. A point whose Y is the close of its candle keeps its candle.
Events
The graph sends the events of its points for the candles too.
| Event | Sent when |
|---|---|
Graph.DataPointSelected(series, index) |
A click, a key or SelectPoint selects a candle, or the selection is cleared (null, -1). |
Graph.DataPointHovered(series, index) |
The pointer moves onto a candle, or off it (null, -1). |
Graph.DataPointAdded(series, point) |
AddCandle adds a candle. The point is its X and its close. |
Mouse and keyboard
| Input | Does |
|---|---|
| Pointer over a candle | The tooltip of the plot shows the label, X, and the open, the high, the low and the close, as in "Grain: 3, Open 12, high 15, low 11, close 14". |
| Click | Selects the candle, or clears the selection when it is selected. A click on empty space clears it. |
| Left, Right, D-pad, left stick | Move the selection along the series. |
| Escape | Clears the selection. |
The pointer finds a candle anywhere from its low to its high across the width of its body, and a few pixels above and below, so a flat candle is easy to point at. A candle comes before a bar or a point under it. The wheel, a drag and a double click zoom and pan the graph, as in Graph.
In a bar chart
A price with its volume is a Bar chart with a candle series and a bar series:
- The candles stand at the X of the bar groups and draw over the bars. The bars of the other series share the whole group.
- An axis with only candles fits the candles. The bars on the other axis grow from 0.
- Put the volume on the right axis with a
y2-maxof about three times its highest value, so its bars stay in the lower third, under the candles.
Performance
- The candles are plain rectangles in the mesh of the graph, so 1,000 candles draw about as fast as a line of 1,000 points.
- At rest the graph does no work, and no scheduled item runs. The grow-in of
Animateruns only while a series grows. - The hit test, the fitted view, the draw and a
CandleDataset to equal candles allocate nothing. - Each change of the points checks each candle against its point once. For a live series, set
max-items. - The
Candlestext is made when it is read, for the UI Builder. In code, readCandleDataorGetCandle.
Styling
| Variable | On | Description |
|---|---|---|
--tb-graph-candle-up |
tb-graph |
The color of a rising candle. Default --tb-color-success. |
--tb-graph-candle-down |
tb-graph |
The color of a falling candle. Default --tb-color-danger. |
The legend row of a candle series has the classes of a series in Graph: tb-graph__series, its swatch and its label. The swatch shows the color of a rising candle.
A market where a rise is blue and a fall is orange:
.market-graph {
--tb-graph-candle-up: rgb(51, 153, 255);
--tb-graph-candle-down: rgb(255, 153, 51);
}
The CandleSeriesDemo scene shows a series with only its candles, a market that adds a day at a time with the average of five days as a line, the units sold as bars on the right axis, and three looks with the color attributes. The status tells the selected and the pointed candle.