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: ?{date}
open: ?{open}
high: ?{high}
low: ?{low}
close: ?{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: ?{date}
open: ?{open}
high: ?{high}
low: ?{low}
close: ?{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: ?{date}
open: ?{open}
high: ?{high}
low: ?{low}
close: ?{close}
increasing:
line:
color: "#1f77b4"
decreasing:
line:
color: "#ff7f0e"
filters:
- ?{stock = 'AAPL'}
- name: OHLC Plot for MSFT
model: ${ref(ohlc-data-multi)}
props:
type: ohlc
x: ?{date}
open: ?{open}
high: ?{high}
low: ?{low}
close: ?{close}
increasing:
line:
color: "#2ca02c"
decreasing:
line:
color: "#d62728"
filters:
- ?{stock = 'MSFT'}
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"
A schema to validate plotly trace properties
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: 'array' #(1)!
closesrc: 'string' #(2)!
customdata: 'array' #(3)!
customdatasrc: 'string' #(4)!
decreasing:
line:
color: 'any' #(5)!
dash: 'string' #(6)!
width: 'number' #(7)!
high: 'array' #(8)!
highsrc: 'string' #(9)!
hoverinfo: 'array' #(10)!
hoverinfosrc: 'string' #(11)!
hoverlabel:
align: 'array' #(12)!
alignsrc: 'string' #(13)!
bgcolor: 'color | array' #(14)!
bgcolorsrc: 'string' #(15)!
bordercolor: 'color | array' #(16)!
bordercolorsrc: 'string' #(17)!
font:
color: color | array
colorsrc: 'string' #(18)!
family: 'string | array' #(19)!
familysrc: 'string' #(20)!
lineposition: 'array' #(21)!
linepositionsrc: 'string' #(22)!
shadow: 'string | array' #(23)!
shadowsrc: 'string' #(24)!
size: number | array
sizesrc: 'string' #(25)!
style: 'array' #(26)!
stylesrc: 'string' #(27)!
textcase: 'array' #(28)!
textcasesrc: 'string' #(29)!
variant: 'array' #(30)!
variantsrc: 'string' #(31)!
weight: 'integer | array' #(32)!
weightsrc: 'string' #(33)!
namelength: 'integer | array' #(34)!
namelengthsrc: 'string' #(35)!
split: 'boolean' #(36)!
hovertext: 'string | array' #(37)!
hovertextsrc: 'string' #(38)!
ids: 'array' #(39)!
idssrc: 'string' #(40)!
increasing:
line:
color: 'any' #(41)!
dash: 'string' #(42)!
width: 'number' #(43)!
legend: 'string' #(44)!
legendgroup: 'string' #(45)!
legendgrouptitle:
font:
color: any
family: 'string' #(46)!
lineposition: 'string' #(47)!
shadow: 'string' #(48)!
size: number
style: 'any' #(49)!
textcase: 'any' #(50)!
variant: 'any' #(51)!
weight: 'integer' #(52)!
text: 'string' #(53)!
legendrank: 'number' #(54)!
legendwidth: 'number' #(55)!
line:
dash: 'string' #(56)!
width: 'number' #(57)!
low: 'array' #(58)!
lowsrc: 'string' #(59)!
metasrc: 'string' #(60)!
name: 'string' #(61)!
opacity: 'number' #(62)!
open: 'array' #(63)!
opensrc: 'string' #(64)!
showlegend: 'boolean' #(65)!
stream:
maxpoints: 'number' #(66)!
token: 'string' #(67)!
text: 'string | array' #(68)!
textsrc: 'string' #(69)!
tickwidth: 'number' #(70)!
type: ohlc
uid: 'string' #(71)!
visible: 'any' #(72)!
x: 'array' #(73)!
xaxis: 'string' #(74)!
xcalendar: 'any' #(75)!
xhoverformat: 'string' #(76)!
xperiodalignment: 'any' #(77)!
xsrc: 'string' #(78)!
yaxis: 'string' #(79)!
yhoverformat: 'string' #(80)!
zorder: 'integer' #(81)!
- Sets the close values.
- Sets the source reference on Chart Studio Cloud for
close
. - 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 source reference on Chart Studio Cloud for
customdata
. - 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.
- Sets the source reference on Chart Studio Cloud for
high
. - 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 source reference on Chart Studio Cloud for
hoverinfo
. - 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 source reference on Chart Studio Cloud for
align
. - Sets the background color of the hover labels for this trace
- Sets the source reference on Chart Studio Cloud for
bgcolor
. - Sets the border color of the hover labels for this trace.
- Sets the source reference on Chart Studio Cloud for
bordercolor
. - Sets the source reference on Chart Studio Cloud for
color
. - HTML font family - the typeface that will be applied by the web browser. The web browser can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
- Sets the source reference on Chart Studio Cloud for
family
. - Sets the kind of decoration line(s) with text, such as an under, over or through as well as combinations e.g. under+over, etc.
- Sets the source reference on Chart Studio Cloud for
lineposition
. - Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
- Sets the source reference on Chart Studio Cloud for
shadow
. - Sets the source reference on Chart Studio Cloud for
size
. - Sets whether a font should be styled with a normal or italic face from its family.
- Sets the source reference on Chart Studio Cloud for
style
. - Sets capitalization of text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.
- Sets the source reference on Chart Studio Cloud for
textcase
. - Sets the variant of the font.
- Sets the source reference on Chart Studio Cloud for
variant
. - Sets the weight (or boldness) of the font.
- Sets the source reference on Chart Studio Cloud for
weight
. - 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. - Sets the source reference on Chart Studio Cloud for
namelength
. - Show hover information (open, close, high, low) in separate labels.
- Same as
text
. - Sets the source reference on Chart Studio Cloud for
hovertext
. - 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 source reference on Chart Studio Cloud for
ids
. - 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 reference to a legend to show this trace in. References to these legends are legend, legend2, legend3, etc. Settings for these legends are set in the layout, under
layout.legend
,layout.legend2
, etc. - Sets the legend group for this trace. Traces and shapes 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 can only apply a font if it is available on the system where it runs. Provide multiple font families, separated by commas, to indicate the order in which to apply fonts if they aren't available.
- Sets the kind of decoration line(s) with text, such as an under, over or through as well as combinations e.g. under+over, etc.
- Sets the shape and color of the shadow behind text. auto places minimal shadow and applies contrast text font color. See https://developer.mozilla.org/en-US/docs/Web/CSS/text-shadow for additional options.
- Sets whether a font should be styled with a normal or italic face from its family.
- Sets capitalization of text. It can be used to make text appear in all-uppercase or all-lowercase, or with each word capitalized.
- Sets the variant of the font.
- Sets the weight (or boldness) of the font.
- 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. When having unranked or equal rank items shapes would be displayed after traces i.e. according to their order in data and layout. - 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.
- Sets the source reference on Chart Studio Cloud for
low
. - Sets the source reference on Chart Studio Cloud for
meta
. - Sets the trace name. The trace name appears as the legend item and on hover.
- Sets the opacity of the trace.
- Sets the open values.
- Sets the source reference on Chart Studio Cloud for
open
. - Determines whether or not an item corresponding to this trace is shown in the legend.
- Sets the maximum number of points to keep on the plots from an incoming stream. If
maxpoints
is set to 50, only the newest 50 points will be displayed on the plot. - The stream id number links a data trace on a plot with a stream. See https://chart-studio.plotly.com/settings for more details.
- 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 source reference on Chart Studio Cloud for
text
. - Sets the width of the open/close tick marks relative to the x minimal interval.
- Assign an id to this trace, Use this to provide object constancy between traces during animations and transitions.
- 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.46By default the values are formatted usingxaxis.hoverformat
. - Only relevant when the axis
type
is date. Sets the alignment of data points on the x axis. - Sets the source reference on Chart Studio Cloud for
x
. - 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.46By default the values are formatted usingyaxis.hoverformat
. - Sets the layer on which this trace is displayed, relative to other SVG traces on the same subplot. SVG traces with higher
zorder
appear in front of those with lowerzorder
.