How to build a Curved Gradient Area Chart in Tableau Software

The Tableau Conference Europe 2019 in Berlin was the occasion to reveal the technique behind my curved gradient area chart. For those who were not there, let me share with you again the polygon trick behind.

The TCE session shared with my friend Klaus Schulte

What is a Gradient Chart ?

A gradient chart is any chart using color gradients in its design. First, let me share with you one design I personally enjoy.

The Flow / Sankey diagram of Adyen's income statement
Nadieh Bremer Financial Flow Chart

Such a clean design, I love Nadieh Bremer’s work!

The usefulness of gradient is often arguable, displaying transition, encoding scale, aesthetic purposes? It is not the main point here. The point is to show that gradient can be developped in Tableau and the technique can be used for other designs.

Lately, I used gradient for a Game of Thrones project to visualize word occurences by episodes. I used gradient in this design but I also had a curvy aspect to my area chart. Again, the usefulness of curved lines is arguable, not the point here 🙂

Storm of Words Visualization

Explanation

Before enjoying a good piece of nerdiness, let me explain the basics behind the technique I will share here.

You can already download the workbook here.

Curves

In Tableau, when you use the line mark type, a linear curve appear on the screen.

A line in Tableau

There is no easy way to make it curvy. The curved version with the same data as above would look like this.

A curved line in Tableau

To give a curvy aspect to a line chart in Tableau, we need to think that curved line as a basic line but with some intermediate/extra points between the current value and the next value displayed. The extra points must be distributed between the two differently than linearly if you want to give your line a curvy aspect.

Curvy aspect performed with the sigmoid function

If you already want to know more about the technique behind, I invite you to read Ken Flerlage blogpost about data densification

Gradients

In design, gradient is basically a continuous transition between two or more colors. In Nadieh Bremer’s flow chart, the gradient is bewteen the green and the white/transparent green with a continuous change in opacity. In my area chart, the gradient is between the blue dark and the yellow with a continuous change using the Inferno color palette.

Knowing that, the transition in color or continuous change can be think as a number of stacked elements of different colors. But you need enough stacked element to make it look smooth.

20 stacked elements with Inferno Palette

For example, 20 is not enough in the design above, you need more to achieve that continuous change.

100 stacked elements with Inferno Palette

The same example with 100 elements stacked aside of each other produced a far more better gradient design.

We can use the same idea to draw gradients in more complex designs. A number of element stacked on top each other, polygons for example. Then I “only” need to calculate the coordinates of those polygons depending on how many polygons I use in my design.

Gradient with two stacked polygons

Data

Like often, I will use polygons to build my gradients. I need several datasets to add the necessary extra points:

  • A main dataset where I have the data I want to display
  • A secondary dataset to give the curved aspect
  • A third and light dataset to encode position
  • A fourth dataset to create my gradient

Let’s dig into it shall we? My main data is a monthly evolution already agregated and prepared. value_1 host the next value, it will be useful for the curved aspect.

Main Dataset

The model dataset hosts 50 rows to add extra points in my design to give the curved aspect. Later, the sigmoid function will be performed on this dataset.

Model Dataset

The position dataset is only two rows, 0 for encode bottom position of my points, 1 for encode top.

Position Dataset

The stack dataset is 100 rows and represent the number of polygons needed to give the gradient aspect. One color will be assigned for each polygon. It can be reduced later.

Stack Dataset

Finally, as often, we will perform a cartesian product between the four. And that is why you previously need to agregate your main dataset! You can imagine the number of rows produced…

The cartesian product

Data can be downloaded here.

Calculation

First, we need to calculate the curved aspect of our basic line. We will use the model dataset and apply the sigmoid function on it.

t_f : range of the sigmoid function

([T]-1)/{max([T])-1}*12-6

sigmoid : value of the sigmoid function

1/(1+exp(-[t_f]))

x : horizontal axis of our curve based on an id [Cat] in the main dataset and the previously calculated t_f

[Cat]+([t_f]+6)/12

y : sigmoid function applied to my extra points between the current value and the next value

[@value_current]+[sigmoid]*([@value_next]-[@value_current])

y_f : extra step to deal with the duplicated lines of my other cartesian products

{FIXED [Cat],[T]: min([y])}

First step plotted

Then we can deal with the coordinates of our polygons based on the stack and position dataset.

Stack_bottom : minimum y value taken by each polygon stack (depending on my main data)

{max([Value])}/{max([Stack])}*[Stack]
-{max([Value])}/{max([Stack])}

Stack_maximum : maximum y value taken by each polygon stack (depending on my main data)

{max([Value])}/{max([Stack])}*[Stack]

Stack_bottom and stack_top for only two stacks, max value of my main dataset equal 9

Position_Bottom : real bottom position of each point, minimum between minimum y value of the stack and the y value of the curve calculated earlier.

avg(min([y_f],[Stack_Bottom]))

Position_Top : real top position for each point, minimum between maximum y value of the stack and the y value of the curve calculated earlier. We add a constant for a better rendering in Tableau Public.

avg(min([y_f],[Stack_Top]+{max([@value_current])/100}))

Position_y : choose between the position_top or position_bottom depending on the position dataset

IF min([Position])=0
THEN [Position_Top]
ELSE [Position_Bottom]
END

Path : order of the point to draw the polygons

IF [Position]=0 THEN [x] ELSE 1000-[x] END

And that’s it, you just need to use those fields as displayed below. You can try to reduce the number of extra points needed using Stack and T field as context filter.

curved gradient area chart plotted

Workbook can be downloaded here

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