A candlestick chart: renders open-high-low-close (OHLC) financial and price data intervals as candlesticks with wicks and colored bodies.
Use a candlestick chart to visualize asset prices, stock movements, and trading volatility over time intervals (minutes, hours, days, months).
Example
data = [
%{label: "09:00", open: 100.0, high: 105.0, low: 98.0, close: 104.0},
%{label: "09:05", open: 104.0, high: 106.0, low: 101.0, close: 102.0}
]
chart = Plotto.CandlestickChart.new!(data, title: "AAPL - 5m")
svg = Plotto.to_svg!(chart)
png = Plotto.to_png!(chart)
Summary
Types
One OHLC data point: interval :label, numeric :open, :high, :low, :close,
and optional :attrs attribute map.
Chart options, after defaults have been applied. Stored in this resolved map
form on the chart struct (t/0's :opts field).
One candlestick series: optional :name and its list of ohlc_item/0 points.
The candlestick chart struct.
Functions
Builds a candlestick chart. Returns {:ok, chart} or {:error, reason}.
Same as new/2, but returns the t/0 struct directly and raises ArgumentError
if validation fails.
Types
@type ohlc_item() :: %{ :label => String.t(), :open => number(), :high => number(), :low => number(), :close => number(), optional(:attrs) => %{optional(String.t()) => String.t()} }
One OHLC data point: interval :label, numeric :open, :high, :low, :close,
and optional :attrs attribute map.
@type options() :: %{ width: pos_integer(), height: pos_integer(), title: String.t() | nil, colors: [String.t()], legend: :top_left | :top_center | :top_right | :left_top | :left_middle | :left_bottom | :right_top | :right_middle | :right_bottom | :bottom_left | :bottom_center | :bottom_right | :top | :bottom | nil, legend_orientation: :vertical | :horizontal, bullish_color: String.t(), bearish_color: String.t(), tooltip: :data | :native | :title | false | nil | function(), y_max: number() | nil, y_min: number() | nil, y_max_soft: boolean(), y_min_soft: boolean(), y_max_guide: false | {:solid | :dashed | :dotted, String.t()}, y_min_guide: false | {:solid | :dashed | :dotted, String.t()}, value_prefix: String.t() | nil, value_suffix: String.t() | nil, x_guidelines: false | {:solid | :dashed | :dotted, String.t()}, y_guidelines: false | {:solid | :dashed | :dotted, String.t()} }
Chart options, after defaults have been applied. Stored in this resolved map
form on the chart struct (t/0's :opts field).
One candlestick series: optional :name and its list of ohlc_item/0 points.
The candlestick chart struct.
Functions
Builds a candlestick chart. Returns {:ok, chart} or {:error, reason}.
data can be either a flat list of ohlc_item/0 maps or a list of series/0
maps containing OHLC points.
Options
:width- chart width in pixels. Defaults to600.:height- chart height in pixels. Defaults to400.:title- optional chart title centered above the plot. Defaults tonil.:bullish_color- hex color for bullish candles (close >= open). Defaults to"#26A69A".:bearish_color- hex color for bearish candles (close < open). Defaults to"#EF5350".:legend- optional legend position::top_left,:top_center,:top_right,:left_top,:left_middle,:left_bottom,:right_top,:right_middle,:right_bottom,:bottom_left,:bottom_center, or:bottom_right. Defaults tonil.:legend_orientation- optional legend layout orientation::verticalor:horizontal. Applies when:legendis a top or bottom position. Defaults to:vertical.:y_max- optional maximum target or upper bound for the Y axis. Defaults tonil.:y_min- optional minimum target or lower bound for the Y axis. Defaults tonil.:y_max_soft- boolean indicating if:y_maxcan be exceeded if data values are greater. Defaults totrue.:y_min_soft- boolean indicating if:y_mincan be exceeded if data values are smaller. Defaults tofalse.:y_max_guide- optional horizontal guide line drawn aty_max:false,true, or{:solid | :dashed | :dotted, color}. Defaults tofalse.:y_min_guide- optional horizontal guide line drawn aty_min:false,true, or{:solid | :dashed | :dotted, color}. Defaults tofalse.:value_prefix- optional string prefix prepended to numeric values (e.g."$","€"). Can also be passed as:prefix. Defaults tonil.:value_suffix- optional string suffix appended to numeric values (e.g."%"). Can also be passed as:suffix. Defaults tonil.:x_guidelines- optional vertical guidelines drawn at each category:false,true, or{:solid | :dashed | :dotted, color}. Defaults tofalse.:y_guidelines- optional horizontal guidelines drawn at each Y-axis tick:false,true, or{:solid | :dashed | :dotted, color}. Defaults tofalse.
Same as new/2, but returns the t/0 struct directly and raises ArgumentError
if validation fails.