View Source Tucan.Finance (tucan v0.4.1)
Financial plots.
This module provides specialized financial plots like candlestick/7
.
Summary
Functions
Plots a candlestick chart from OHLC data.
Functions
Link to this function
candlestick(plotdata, timestamp, open, high, low, close, opts \\ [])
View Source@spec candlestick( plotdata :: Tucan.plotdata(), timestamp :: String.t(), open :: String.t(), high :: String.t(), low :: String.t(), close :: String.t(), opts :: keyword() ) :: VegaLite.t()
Plots a candlestick chart from OHLC data.
timestamp
is expected to correspond to the beginning of the chart's period.
Options
Data Options
:only
- A subset of fields to pick from the data. Applicable only if tabular data are provided.
Styling Options
:clip
(boolean/0
) - Whether a mark will be clipped to the enclosing group’s width and height.:fill_opacity
(number/0
) - The fill opacity of the plotted elements. The default value is1
.:height
(pos_integer/0
or:container
) - Height of the plot. Can either be the height in pixels or:container
to indicate that the height of the plot should be the same as its surrounding container.:title
(String.t/0
) - The title of the graph:width
(pos_integer/0
or:container
) - Width of the plot. Can either be the width in pixels or:container
to indicate that the width of the plot should be the same as its surrounding container.
Interactivity Options
:tooltip
(boolean() | :data | :encoding
) - The tooltip text string to show upon mouse hover or an object defining which fields should the tooltip be derived from. Can be one of the following::encoding
- all fields from encoding are used:data
- all fields of the highlighted data point are usedtrue
- same as:encoding
false
,nil
- no tooltip is used
:zoomable
(boolean/0
) - Whether the plot will be zoomable or not. If set totrue
you will be able to pan and zoom the plot with your mouse. You can reset to the original view with a double click. The default value isfalse
.
Examples
Tucan.Finance.candlestick(:ohlc, "date", "open", "high", "low", "close",
width: 400,
tooltip: true
)
|> Tucan.Axes.set_y_title("Price")
{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"url":"https://vega.github.io/editor/data/ohlc.json"},"layer":[{"encoding":{"x":{"field":"date","type":"temporal"},"y":{"axis":{"title":"Price"},"field":"low","scale":{"zero":false},"type":"quantitative"},"y2":{"field":"high","type":"quantitative"}},"mark":{"fillOpacity":1,"tooltip":true,"type":"rule"}},{"encoding":{"color":{"condition":{"test":"datum.open < datum.close","value":"#06982d"},"value":"#ae1325"},"x":{"field":"date","type":"temporal"},"y":{"axis":{"title":"Price"},"field":"open","scale":{"zero":false},"type":"quantitative"},"y2":{"field":"close","type":"quantitative"}},"mark":{"fillOpacity":1,"tooltip":true,"type":"bar"}}],"width":400}