In this tutorial, we’ll demonstrate how to draw an Open-High-Low-Close Chart (or OHLC Chart) in Glimpse, which is a chart used to visualize price movements over time. A OHLC Chart displays multiple bits of price information such as the open price, close price, highest price and lowest price.
First, add in the data by going Data > Sample Data > ohlc.json from the top menu.
Then, under Visual > Mark in the Inspector panel, set the Mark Type to Rule.
Drag the field date into the X encoding. After, in the Inspector panel, change the Measure type to Temporal and under Visual > Encoding > Time Unit tick Month and Date. Also, deactivate Title.
Next, drag the fields high into the Y encoding and low into the Y2 encoding. Also, deactivate Title.
To reduce the amount of empty space on the graph, press high in Y and in the Inspector panel go Visual > Encoding > Scale > Domain untick Include Zero.
To set the color of the bars, a Calculate data transform needs to be created. On the top menu go Insert > Transform > Calculate. In the Inspector panel, enter “Bar Coloring” for the Title, “bar_color” for the Output, and for Calculate enter:
datum.open < datum.close ? '#06982d' : '#ae1325'
Then enable the transform to activate it.
Now that the bar_color token has been created, drag it into the Color encoding.
Deactive Scale in the Inspector panel so that the correct colors appear.
To thicken the marks, go Visual > Mark > Size and enter 2 pt for Size.
Now to create the ‘open’ and ‘close’ ticks, create a new layer by going Insert > Layer > Tick from the top menu.
Drag the field date into the X encoding. After, in the Inspector panel, change the Measure type to Temporal and under Visual > Encoding > Time Unit tick Month and Date.
After, drag the field open into the Y encoding.
Then, drag the bar_color token into the Color encoding and in the Inspector panel deactivate Scale.
In Visual > Mark > Size set the Width to 10 pt.
To adjust the position of the ticks, go Position and enter -3 pt in the X Offset.
To make the ticks more visible, go Stroke and enter 4 pt for the Thickness.
After, go under Color and set the Opacity to 100%.
To create the ‘close’ tick, right-click or ctrl-click the Tick layer under Layers in the Outline and select Duplicate Selection from the menu.
This will create a duplicate Tick layer:
Now, move the field close into the Y encoding (replacing open).
Then, change the position by go Visual > Mark > Position and enter 3 pt in the X Offset.
This concludes this tutorial on drawing a OHLC Chart. If you want to further customize your chart, please read the documentation.