In this blog post I will be talking through the steps to making a line chart in which the colour of the line is controlled by a parameter. This can be useful when you want to show all values for context but don’t want too many colours and feel a different colour would be more effective than highlighting. You can follow the along using sample superstore. This is the finished chart:

Step one: Right click and drag order date to the columns shelf. From the dialogue box that appears select continuous month (order date) and click okay [Image 1]. Then double click profit so that it automatically adds to the rows shelf and drag segment to the marks shelf. This will be applied to detail by default.


Image 1: Select continuous month (order date) and click okay.
Image 2: Your chart after completing step one.

Step two: Currently all the segment lines are coloured the same. We now want to set up the parameter to be able to select which line will be a different colour. You can set up a parameter in a few different ways but, in this instance, I am going to right click on the segment dimension, then select create on the drop down that appears and then select parameter on the next drop down [Image 3]. A box called create parameter will appear. You will notice that data type already has the value string as this is the data type of the dimension that we created the parameter from. The current value reads consumer as this is first in the alphabetically sorted list of values generated from the dimension. The only field we need to change is the name field at the top of the dialogue box. This will currently read segment parameter. It is useful to change this to something that can guide the user, for example ‘Select segment of interest’. Now click OK [Image 4]. You will see that ‘select segment of interest’ has now appeared in the parameters section.

Image 3: Creating your parameter from a dimension.
Image 4: Completing the create parameter dialogue box.

Step three: Right click on the parameter and then select show parameter control [Image 5]. The parameter control will appear to the right of the chart, however, you will notice that if you currently use the control to change the parameter value then nothing happens to the chart. This is because the parameter control needs to be linked to the chart in some way. This can be done with a calculated field.

Image 5: Right click on the parameter and then select show parameter control.

Step four: To be able to make it possible for the parameter control to change the colour of segment we need to create a calculated field linking the two. This can be done by right clicking on the select segment of interest parameter and then selecting create, followed by calculated field [Image 6]. In the calculated field box that pops up delete the calculation name provided and re-name the field with a suitable title. I called mine parameter control link. Selecting to create a calculated field from the parameter pill results in Tableau automatically adding the parameter field into the calculation window for you (in purple). We can then set this equal to the segment field (see calculation below) and click OK [Image 7]. The equation results in a Boolean and should appear under dimensions. Select the calculated field and drag it onto colour. If you change the parameter control value you will see that the colour of the segment now changes according to the selected value, however, the chart still needs a little refining.

Image 6: You can create your calculated field directly from the parameter.
Image 7: The calculated field that links parameter to segment.
Image 8: The chart at the end of step four.

Step five: The colour combination means the selected segment line is competing for attention with the other segments. To rectify this, the colours for the other segments need to be toned down and the line of the selected segment needs to be brought in front of the other two. To add these finishing touches, click the analysis tab and then go down to legends. Select legends and then select colour legend [Image 9]. The legend will pop up to the right of the worksheet [Image 10]. Click on the true alias and drag it above false. The line corresponding to the segment selected in the parameter will now be on top of the others. The next thing to do is to make the other segments have a less conspicuous colour. Double click on the coloured square next to the false alias and then select the drop down underneath select colour palette. Go down to the Seattle Grays palette and select the lightest grey (second from the bottom). The lines will now provide context without distracting from the selected parameter. You could now either right-click on true and then select edit alias and re-name the colours to something more meaningful. I changed true to selected segment and then repeated the steps for false and re-named this other segments. If you think the colour is self-explanatory or intend to indicate the meaning of the colours in your dashboard text you can click the carrot to the top-right of the legend and click hide card. You can complete the formatting for the chart as suits you. I formatted out the grid lines.

Image 9: How to make the colour legend appear.
Image 10: The legend will pop up to the right of the worksheet.
Image 11: The finished chart.

Feature Image: Photo by David Pisnoy on Unsplash