# 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.

## 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.

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 🙂

## Explanation

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

### Curves

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

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

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.

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.

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

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.

## 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.

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.

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

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.

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…

## 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])}

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.