top of page

From a Line to a Spark!

What are sparkline charts? Sparkline charts are small line charts that are vertically stacked together instead of combining them all on one axis.


Why would you use a sparkline chart over a regular line chart? You can see the variation of a metric over time for each dimension element. They are used for seeing trends quickly. Think of stocks for example, you see the peaks and valley next to each stock ticker.


Here is an example from Tableau Public in a dashboard built by Thiago Lima. He added dots on the highest and lowest values for these sparklines.



So how do you create these sparklines? A very simple example is below.


How to Make a Sparkline Chart


In Tableau Public, with connecting to the Sample Superstore dataset, I placed Order Date on the Columns shelf formatted as Month Continuous.

I then placed State on the Rows shelf.

Then I placed Sales on the Rows shelf next to State.



Now for the more complex item of adding a circle to each sparkline reflecting the minimum and maximum values.


Method 1


You can create a dual axis chart (using a line and circle combination) by creating the below calculated field.


Min / Max Label

IF SUM([Sales]) = WINDOW_MAX(SUM([Sales])) then 'Max'

ELSEIF SUM([Sales]) = WINDOW_MIN(SUM([Sales])) then 'Min'

Else ''

END


In my chart I dragged a second Sales to the Rows shelf and made a dual axis.

I synchronized the axes and then changed the second SUM(Sales) to a Circle.



I added the Min / Max label calculation to the Label Marks card and then to the Color Marks card. This added three colors for the circles overlapping the lines.



I then right-clicked on the blue value in the color legend and selected Hide.



This removes the blue circles and only minimum and maximum values remain!



I then created the below calculation to attach the actual sales values to the labels on the circles.


Min / Max Values

IF SUM([Sales]) = WINDOW_MAX(SUM([Sales])) then SUM([Sales])

ELSEIF SUM([Sales]) = WINDOW_MIN(SUM([Sales])) then SUM([Sales])

Else NULL

END


I also had to check the option to allow marks to overlap.



Method 2


In this other method I used Tableau's Measure Names and Measure Values feature. I created two calculated fields below:


Window Max

IF SUM([Sales]) = WINDOW_MAX(SUM([Sales])) then SUM([Sales])

ELSE NULL

END


Window Min

IF SUM([Sales]) = WINDOW_MIN(SUM([Sales])) then SUM([Sales])

ELSE NULL

END


The first one will only pull the maximum sales value from the worksheet (or window). The second pulls the minimum value.


I placed Measure Values on the Rows shelf next to SUM([Sales]).

I created a Dual Axis and synchronized the axes.

I then changed the Measure Values Marks card to a circle.

I then moved Measure Names to the Color Marks card.


The chart appeared as below!



Feel free to try either sparkline method.




Recent Posts

See All

Comentarios


bottom of page