Monday Minis: How to Create a Candlestick Chart in Tableau

Candlestick charts get their name from their resemblance to a candle stick (clearly!). They can be easily identified by a narrow line and a thicker bar on top. Both “bars” represent connections/differences between two values. While research tells me that the candlestick chart originated in Japan over 100 years prior to the stock market’s use of them in the West, they now are widely used in stock market analysis, but still have various other possible uses.

As they relate to stocks, candlestick charts show both the high/low trading price of a stock as well as the closing/opening price. Stock prices can vary throughout a day, so the candlestick provides a clear analysis on volatility as well as overall difference gained/loss each day (open/close change).

Additionally, these charts can add in an element of color to show if a day’s closing price was up or down from the prior day. This helps to see the movement in the data and indicate to investors patterns when a stock might rise or fall.

This Monday Mini will show you how to build the candlestick chart and then show a few useful alternatives for “the real world”. To check out the full Tableau workbook, you can go view and/or download it here.

We are going to use Yahoo Finance’s Teladoc stock data (but you can download any stock data you wish to try this out). Just select the Historical Data section, set your timeframe, and click download. The data comes with the four metrics we need to build this candlestick chart: high, low, open, and close.

The main building blocks of a candle stick chart are two Gantt charts set up on a dual axis each with a different size (the horizontal thickness of the “bar”) and range (the vertical length of the “bar”).

Let’s get started. (Note in my example, I limited the data to a few months.)

STEP 1. Create Two Calculations

  • Calculate the difference (range) between the low and high values. In this case it’s [High]-[Low].
  • Calculate the difference (range) between the open and close values. In this case it’s [Close-Open].

STEP 2. Create the 1st Gnatt Chart

  • Drag your Continuous Measure (Date) to Columns and set it to Exact Day so that the pill is green
  • Drag the Low measure to Rows – This will be the point by which the difference extends from. Tableau will default the view to a line chart.
  • Change the Mark to Gantt – At this point the view should have a number of, what looks like, horizontal dashes.
  • Add the High/Low calculation to the Size Mark. This will result in “floating bars”.
Step 1 and 2 Complete with the first Gantt Chart

STEP 3. Create the 2nd Gnatt Chart

  • Drag the Open measure to Rows – This is the point by which the difference extends from
  • Change the Mark to Gantt
  • Add the Open/Close calculation to the Size Mark (replace the High/Low calculation that is on size, which is left over from step 2).

STEP 4. Dual Axis, Format Size, and Add Color

  • Right click on a pill on the Rows shelf and select Dual Axis
  • Right click on the axis header to Synchronize the axes
  • Adjust the size of the two Gantt charts. The size of the first (Low/High) mark should be set very small to resemble a line. This gives the overall range of the data. The second Gantt mark should be slightly larger. This will show the inner subset which is the actual open and close. Adjust the size as needed.
  • Create a boolean calculation for the color using the [Close/Open] calculation and set that to >=0
  • Add the color calculation to the Color Mark on the second Gantt chart (the thicker one) and format as necessary.

Additional Notes: In candlestick charts, you do not need to start the axis at zero (this example doesn’t include zero).

Your final view should look something like this:

All Steps Completed – Format as you wish

There are many additional ways to use the concepts from a candlestick chart, specifically how you can add Gantt charts to your visualization or combine Gantt charts with other chart types to show ranges using a starting value and then a difference value for the size.

This viz on European Disease Prevalence uses a Gantt chart to plot the middle 50% of values with a jittered scatterplot on top.

A viz I created on Smoking Prevalence also uses the “floating bar” to show a mid-range. While I chose to show all countries as distinct dots, an alternative would be to plot the lowest and highest value and connect them with a line, just like this tutorial.

Another use of the Gantt chart (albeit this one doesn’t use two dual axis Gantt charts), is this Presidential Age viz in which I show the age of each president and then the change in age to the next one using a Gantt floating bar.

As always, check out the full viz for more information and how to reverse engineer it. I hoped you enjoyed this Monday Mini tutorial!

Reach out if you have questions!

Cheers,

Lindsay

Final Candlestick viz – Click to view

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s