Ohlc
Overview
The ohlc
trace type is used to create OHLC (Open, High, Low, Close) charts, which are commonly used to visualize stock market data or financial data over time. OHLC charts represent price movements for a given period using vertical bars for high and low prices, and tick marks for open and close prices.
You can customize the colors, bar widths, and date ranges to represent financial data effectively.
Common Uses
- Stock Market Visualization: Displaying price movement data for stocks, currencies, or commodities.
- Financial Time Series: Visualizing price fluctuations over time.
- Trading Analysis: Understanding market trends through candlestick-like visualizations.
Check out the Attributes for the full set of configuration options
Examples
Common Configurations
Here's a simple ohlc
plot showing the Open, High, Low, and Close prices of a stock over time:
You can copy this code below to create this chart in your project:
models:
- name: ohlc-data
args:
- echo
- |
date,open,high,low,close
2023-01-01,100,105,95,102
2023-01-02,102,108,101,107
2023-01-03,107,110,105,109
2023-01-04,109,112,107,111
2023-01-05,111,114,110,113
traces:
- name: Simple OHLC Plot
model: ref(ohlc-data)
props:
type: ohlc
x: query(date)
open: query(open)
high: query(high)
low: query(low)
close: query(close)
increasing:
line:
color: "#17becf"
decreasing:
line:
color: "#ff7f0e"
charts:
- name: Simple OHLC Chart
traces:
- ref(Simple OHLC Plot)
layout:
title:
text: Simple OHLC Chart<br><sub>Stock Price Movements Over Time</sub>
xaxis:
title:
text: "Date"
yaxis:
title:
text: "Price"
This example demonstrates an ohlc
plot with custom bar widths to adjust the spacing between the OHLC bars:
Here's the code:
models:
- name: ohlc-data-width
args:
- echo
- |
date,open,high,low,close
2023-02-01,200,205,195,202
2023-02-02,202,208,201,207
2023-02-03,207,210,205,209
2023-02-04,209,212,207,211
2023-02-05,211,214,210,213
traces:
- name: OHLC Plot with Custom Width
model: ref(ohlc-data-width)
props:
type: ohlc
x: query(date)
open: query(open)
high: query(high)
low: query(low)
close: query(close)
increasing:
line:
color: "#2ca02c"
decreasing:
line:
color: "#d62728"
line:
width: 3
charts:
- name: OHLC Chart with Custom Width
traces:
- ref(OHLC Plot with Custom Width)
layout:
title:
text: OHLC Plot with Custom Width<br><sub>Stock Prices with Custom Bar Width</sub>
xaxis:
title:
text: "Date"
yaxis:
title:
text: "Price"
This example shows an ohlc
plot comparing multiple stocks' Open, High, Low, and Close prices over time:
Here's the code:
models:
- name: ohlc-data-multi
args:
- echo
- |
stock,date,open,high,low,close
AAPL,2023-03-01,150,155,145,152
AAPL,2023-03-02,152,158,150,156
AAPL,2023-03-03,156,160,154,159
MSFT,2023-03-01,250,255,245,252
MSFT,2023-03-02,252,258,250,256
MSFT,2023-03-03,256,260,254,259
traces:
- name: OHLC Plot for AAPL
model: ref(ohlc-data-multi)
props:
type: ohlc
x: query(date)
open: query(open where stock = "AAPL")
high: query(high where stock = "AAPL")
low: query(low where stock = "AAPL")
close: query(close where stock = "AAPL")
increasing:
line:
color: "#1f77b4"
decreasing:
line:
color: "#ff7f0e"
- name: OHLC Plot for MSFT
model: ref(ohlc-data-multi)
props:
type: ohlc
x: query(date)
open: query(open where stock = "MSFT")
high: query(high where stock = "MSFT")
low: query(low where stock = "MSFT")
close: query(close where stock = "MSFT")
increasing:
line:
color: "#2ca02c"
decreasing:
line:
color: "#d62728"
charts:
- name: OHLC Chart with Multiple Stocks
traces:
- ref(OHLC Plot for AAPL)
- ref(OHLC Plot for MSFT)
layout:
title:
text: OHLC Chart with Multiple Stocks<br><sub>Comparing AAPL and MSFT Stock Prices</sub>
xaxis:
title:
text: "Date"
yaxis:
title:
text: "Price"
Attributes
These attributes apply to traces where trace.props.type
is set to ohlc
. You would configure these attributes on the trace with the trace.props
object.
close: 'data array' #(1)!
customdata: 'data array' #(2)!
decreasing:
line:
color: 'color' #(3)!
dash: 'string' #(4)!
width: 'number greater than or equal to 0' #(5)!
high: 'data array' #(6)!
hoverinfo: 'flaglist string. any combination of "x", "y", "z", "text", "name" joined
with a "+" or "all" or "none" or "skip".' #(7)!
hoverlabel:
align: 'enumerated or array of enumerateds , one of ( "left" | "right" | "auto"
)' #(8)!
bgcolor: 'color or array of colors' #(9)!
bordercolor: 'color or array of colors' #(10)!
font:
color: color or array of colors
family: 'string or array of strings' #(11)!
size: number or array of numbers greater than or equal to 1
namelength: 'integer or array of integers greater than or equal to -1' #(12)!
split: 'boolean' #(13)!
hovertext: 'string or array of strings' #(14)!
ids: 'data array' #(15)!
increasing:
line:
color: 'color' #(16)!
dash: 'string' #(17)!
width: 'number greater than or equal to 0' #(18)!
legendgroup: 'string' #(19)!
legendgrouptitle:
font:
color: color
family: 'string' #(20)!
size: number greater than or equal to 1
text: 'string' #(21)!
legendrank: 'number' #(22)!
legendwidth: 'number greater than or equal to 0' #(23)!
line:
dash: 'string' #(24)!
width: 'number greater than or equal to 0' #(25)!
low: 'data array' #(26)!
meta: 'number or categorical coordinate string' #(27)!
opacity: 'number between or equal to 0 and 1' #(28)!
open: 'data array' #(29)!
selectedpoints: 'number or categorical coordinate string' #(30)!
showlegend: 'boolean' #(31)!
text: 'string or array of strings' #(32)!
tickwidth: 'number between or equal to 0 and 0.5' #(33)!
type: ohlc
uirevision: 'number or categorical coordinate string' #(34)!
visible: 'enumerated , one of ( true | false | "legendonly" )' #(35)!
x: 'data array' #(36)!
xaxis: 'subplotid' #(37)!
xcalendar: 'enumerated , one of ( "chinese" | "coptic" | "discworld" | "ethiopian"
| "gregorian" | "hebrew" | "islamic" | "jalali" | "julian" | "mayan" | "nanakshahi"
| "nepali" | "persian" | "taiwan" | "thai" | "ummalqura" )' #(38)!
xhoverformat: 'string' #(39)!
xperiod: 'number or categorical coordinate string' #(41)!
xperiod0: 'number or categorical coordinate string' #(40)!
xperiodalignment: 'enumerated , one of ( "start" | "middle" | "end" )' #(42)!
yaxis: 'subplotid' #(43)!
yhoverformat: 'string' #(44)!
- Sets the close values.
- Assigns extra data each datum. This may be useful when listening to hover, click and selection events. Note that, "scatter" traces also appends customdata items in the markers DOM elements
- Sets the line color.
- Sets the dash style of lines. Set to a dash type string ("solid", "dot", "dash", "longdash", "dashdot", or "longdashdot") or a dash length list in px (eg "5px,10px,2px,2px").
- Sets the line width (in px).
- Sets the high values.
- Determines which trace information appear on hover. If
none
orskip
are set, no information is displayed upon hovering. But, ifnone
is set, click and hover events are still fired. - Sets the horizontal alignment of the text content within hover label box. Has an effect only if the hover label text spans more two or more lines
- Sets the background color of the hover labels for this trace
- Sets the border color of the hover labels for this trace.
- HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the preference in which to apply fonts if they aren't available on the system. The Chart Studio Cloud (at https://chart-studio.plotly.com or on-premise) generates images on a server, where only a select number of fonts are installed and supported. These include "Arial", "Balto", "Courier New", "Droid Sans",, "Droid Serif", "Droid Sans Mono", "Gravitas One", "Old Standard TT", "Open Sans", "Overpass", "PT Sans Narrow", "Raleway", "Times New Roman".
- Sets the default length (in number of characters) of the trace name in the hover labels for all traces. -1 shows the whole name regardless of length. 0-3 shows the first 0-3 characters, and an integer >3 will show the whole name if it is less than that many characters, but if it is longer, will truncate to
namelength - 3
characters and add an ellipsis. - Show hover information (open, close, high, low) in separate labels.
- Same as
text
. - Assigns id labels to each datum. These ids for object constancy of data points during animation. Should be an array of strings, not numbers or any other type.
- Sets the line color.
- Sets the dash style of lines. Set to a dash type string ("solid", "dot", "dash", "longdash", "dashdot", or "longdashdot") or a dash length list in px (eg "5px,10px,2px,2px").
- Sets the line width (in px).
- Sets the legend group for this trace. Traces part of the same legend group hide/show at the same time when toggling legend items.
- HTML font family - the typeface that will be applied by the web browser. The web browser will only be able to apply a font if it is available on the system which it operates. Provide multiple font families, separated by commas, to indicate the preference in which to apply fonts if they aren't available on the system. The Chart Studio Cloud (at https://chart-studio.plotly.com or on-premise) generates images on a server, where only a select number of fonts are installed and supported. These include "Arial", "Balto", "Courier New", "Droid Sans",, "Droid Serif", "Droid Sans Mono", "Gravitas One", "Old Standard TT", "Open Sans", "Overpass", "PT Sans Narrow", "Raleway", "Times New Roman".
- Sets the title of the legend group.
- Sets the legend rank for this trace. Items and groups with smaller ranks are presented on top/left side while with
"reversed"
legend.traceorder` they are on bottom/right side. The default legendrank is 1000, so that you can use ranks less than 1000 to place certain items before all unranked items, and ranks greater than 1000 to go after all unranked items. - Sets the width (in px or fraction) of the legend for this trace.
- Sets the dash style of lines. Set to a dash type string ("solid", "dot", "dash", "longdash", "dashdot", or "longdashdot") or a dash length list in px (eg "5px,10px,2px,2px"). Note that this style setting can also be set per direction via
increasing.line.dash
anddecreasing.line.dash
. - [object Object] Note that this style setting can also be set per direction via
increasing.line.width
anddecreasing.line.width
. - Sets the low values.
- Assigns extra meta information associated with this trace that can be used in various text attributes. Attributes such as trace
name
, graph, axis and colorbartitle.text
, annotationtext
rangeselector
,updatemenues
andsliders
label
text all supportmeta
. To access the tracemeta
values in an attribute in the same trace, simply use%{meta[i]}
wherei
is the index or key of themeta
item in question. To access tracemeta
in layout attributes, use%{data[n[.meta[i]}
wherei
is the index or key of themeta
andn
is the trace index. - Sets the opacity of the trace.
- Sets the open values.
- Array containing integer indices of selected points. Has an effect only for traces that support selections. Note that an empty array means an empty selection where the
unselected
are turned on for all points, whereas, any other non-array values means no selection all where theselected
andunselected
styles have no effect. - Determines whether or not an item corresponding to this trace is shown in the legend.
- Sets hover text elements associated with each sample point. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to this trace's sample points.
- Sets the width of the open/close tick marks relative to the "x" minimal interval.
- Controls persistence of some user-driven changes to the trace:
constraintrange
inparcoords
traces, as well as someeditable: true
modifications such asname
andcolorbar.title
. Defaults tolayout.uirevision
. Note that other user-driven trace attribute changes are controlled bylayout
attributes:trace.visible
is controlled bylayout.legend.uirevision
,selectedpoints
is controlled bylayout.selectionrevision
, andcolorbar.(x|y)
(accessible withconfig: {editable: true}
) is controlled bylayout.editrevision
. Trace changes are tracked byuid
, which only falls back on trace index if nouid
is provided. So if your app can add/remove traces before the end of thedata
array, such that the same trace has a different index, you can still preserve user-driven changes if you give each trace auid
that stays with it as it moves. - Determines whether or not this trace is visible. If "legendonly", the trace is not drawn, but can appear as a legend item (provided that the legend itself is visible).
- Sets the x coordinates. If absent, linear coordinate will be generated.
- Sets a reference between this trace's x coordinates and a 2D cartesian x axis. If "x" (the default value), the x coordinates refer to
layout.xaxis
. If "x2", the x coordinates refer tolayout.xaxis2
, and so on. - Sets the calendar system to use with
x
date data. - Sets the hover text formatting rulefor
x
using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with tickformat "%H~%M~%S.%2f" would display "09~15~23.46"By default the values are formatted usingxaxis.hoverformat
. - Only relevant when the axis
type
is "date". Sets the base for period positioning in milliseconds or date string on the x0 axis. Whenx0period
is round number of weeks, thex0period0
by default would be on a Sunday i.e. 2000-01-02, otherwise it would be at 2000-01-01. - Only relevant when the axis
type
is "date". Sets the period positioning in milliseconds or "M" on the x axis. Special values in the form of "M " could be used to declare the number of months. In this case n
must be a positive integer. - Only relevant when the axis
type
is "date". Sets the alignment of data points on the x axis. - Sets a reference between this trace's y coordinates and a 2D cartesian y axis. If "y" (the default value), the y coordinates refer to
layout.yaxis
. If "y2", the y coordinates refer tolayout.yaxis2
, and so on. - Sets the hover text formatting rulefor
y
using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with tickformat "%H~%M~%S.%2f" would display "09~15~23.46"By default the values are formatted usingyaxis.hoverformat
.