An OHLC chart (open, high, low, close) can be created in Power BI using Deneb/Vega-Lite to visualize stock prices. This example chart uses two Y-axes and contains three overlapping components: a column chart for daily volume, a line chart for daily closing price, and an OHLC chart for the OHLC prices for each day.
This example illustrates a number of Deneb/Vega-Lite features, including:
0-Common Features:
- • uses two different Y-axis scales to prevent one data element from “overwhelming” another
- • includes two legend images (PowerPoint was used to create custom legend images as the standard Vega-Lite legends [or the required syntax] did not provide the desired flexibility)
1-Column Chart:
- • uses a “transform” block to extend the dataset with in-visual calculations of the previous day’s volume, the variance volume, and the volume and price colours according to the day’s relative performance
- • uses a custom “scale” (and domain) for the Y-axis, which is placed on the left
- • uses a custom “expression” for the X-axis (a MM-DD format [complete with zero-padding, if necessary]) for the day label
- • uses a millions format for the volume label on the Y-axis
- • uses a custom “tooltip” block to display the date and volume
2-Line Chart:
- • uses the “interpolate” property (basis) for smoothing
- • uses a custom “scale” (and domain) for the Y-axis, which is placed on the right
3-OHLC Chart:
- • uses “tick” marks for the open (left) and close (right) prices
- • uses a “bar” mark for the vertical rectangle for the high and low prices
- • uses a custom “scale” (and domain) for the Y-axis, which is placed on the right
- • uses a custom “tooltip” block to display the date and OHLC prices
The intent of this example is not to provide a finished visual, but rather to serve as a starting point for further custom visual development.
Also included is the sample PBIX using a 1-year sample of NASDAQ stock volume and price (Microsoft) dataset as a demo.
This example is provided as-is for information purposes only, and its use is solely at the discretion of the end user; no responsibility is assumed by the author.
Greg
Deneb Examples - OHLC Chart.pbix (1.6 MB)