How to Make a Line Graph in Tableau The best chart for visualizing data over time Big insights come from seeing how your data is trending over time. Learn how to make this foundational chart type and how discrete and continuous date fields give you different results.

How to Make a Line Graph in Tableau

The best chart for visualizing data over time

Big insights come from seeing how your data is trending over time. Learn how to make this foundational chart type and how discrete and continuous date fields give you different results.

Hi. This is Ryan with Playfair Data TV. And in this video, I’m going to show you how to make a line graph.

Line graphs are made with the same technical criteria as a bar chart, in that they need zero or more dimensions and one or more measures, with one huge caveat, and that is that they also need at least one date. So technically, line graphs are made with at least one dimension, as long as that first dimension is a date, and then one or more measures.

I’m going to show you how to do this in the Sample Superstore dataset. Because of my number one rule of thumb, measures are the numbers, and then dimensions are what I slice and dice those numbers by, I always start with my number. I always start with my measure.

So I’m just going to double-click on the Sales measure to add it to the view. The default behavior in Tableau was for it to put this Sales measure on the rows shelf, which created this row for sales and a y-axis. And because it’s just one measure, we don’t have a date yet, the mark type was automatically bar. So we got this vertical bar chart.

We’re now going to convert this bar chart to a line graph by adding an element of time to the view. The element of time in the sample dataset is called order date. I’m going to first show you my favorite method for creating line graphs, and then I’ll show you a couple of alternatives.

But first, the way that I like to do it– anytime I’m making a trend over time, I like to use the shortcut of right-clicking on that element of time. While I hold down the right mouse key, I’m going to drag that to the columns shelf and let go. This is similar to when you right-click on a measure so that you can choose a different aggregation.

With dates, it’s very similar. You’re choosing the aggregation, which, in the context of dates, the proper term for that is date part, as well as whether the date is used discrete or continuous. You can see a pretty long list of options here, but I’m going to show you how to very quickly narrow down the selection to get the desired result that you’re looking for.

Let’s pretend that we’re trying to make a line graph that looks at sales by continuous month. These first two choices we’ve got– order date continuous and order date discrete– will look at the date in its most granular form. The sample superstore dataset is at a daily level, so these two options are out. We’re trying to look at things at a monthly level, not a daily level. So we’re going to skip those.

The next set of choices all have a blue icon next to them, which tells me they’re going to use those dates as discrete. Well, just thinking through our logic out loud again, we’re trying to look at sales by continuous month. So all the blue options are out. We’re going to skip those.

The next four choices are actual aggregations– things like count, count distinct, minimum, maximum. Those are irrelevant for what we’re trying to figure out at the moment. So I’m very quickly in this area with five choices. And at this point, I’m simply choosing the correct date part that has a green icon next to it, which tells me it will be continuous.

So in our use case, the one that we’re looking for is the month date part with a green icon next to it. Click OK. You’ve got a line graph.
That’s my highly preferred way. It’s very easy to get to the result you’re looking for, but I’m going to undo and show you an alternative.

If I were to just double-click on Order date, the default mark type is line again. But notice that the columns shelf has our order date, and it’s blue, which means it’s discrete. That means it’s drawing discrete headers for each one of our years.

It’s a coincidence that these are in chronological order, but because they’re discrete, these things aren’t actually connected. They’re discrete unique headers that can be sorted. In fact, if I go to sort this in descending order by using this button under the word Window in the top navigation, Tableau tries to help me out by changing the mark type from line to bar.

It’s because these aren’t actually related. They’re not in chronological order. It was a coincidence that they were by default.

So for that reason, my personal preference is to always use dates as continuous if I’m trying to make some type of continuous trend. But to show you one advantage of leaving this as discrete, there’s a nice feature here. Dates come with an inherent hierarchy to them. And anytime a dimension has a hierarchy, you’ll see a plus sign on its pill. So notice there’s a plus sign. And if I click that plus sign, it will drill down to the next level of the hierarchy.
So it goes from year to quarter. If I click the plus again it goes from quarter to month. If I click the plus again, it goes from month to day.

And I can also go back the other way. If I click this minus sign, it will collapse all the days into their months. And if I click the minus on quarter, it’ll collapse the month into quarters and so on.

There’s a couple of nice things about this. Because these are blue and they’re their own unique pills on the columns shelf, it gives me a little bit of flexibility in how I do this analysis. The first thing is I can choose which date parts to include in my analysis.

So let’s say quarter was irrelevant for what we were trying to look at. Quarter was too granular. I could just click on it and drag it away. And now, we’re just looking at sales by year and then month.

Another nice thing about these are that they’re processed in order. The pills on the columns and rows shelf are processed in order. So at this point, we’ve got a measure called sales, and it’s going to draw a column for a year first and then a column for month second. That’s why it’s down here.

But we can completely flip this analysis by simply dragging one of these pills in front of the other. So if I left-click month and drag it in front of year, it will draw a column for a month first and then a column for year second. So this is a completely different analysis.

Let me show you that one more time. I’m going to undo. So this first view– the default view we were looking at– is looking at a seasonal trend. This is a monthly trend by year. But when we put month in front of year, because it draws a column for month first, this is now a four-year trend by month. So depending on what type of analysis you’re wanting to do, you might want to flip the order of these pills.

One last thing I want to show you– I’m going to remove month for now to get back to that first discrete line graph. I highly prefer, when I’m working with dates and wanting to choose a continuous date part, I like to right click on it and drag it, which I already showed you. But you can also choose both the date part and whether the field’s being used as discrete or continuous once it’s already on the view. It’s just a little bit different.

To get there, you have to click on the pill that you’re trying to change. You can do that by either right clicking on it or clicking this down arrow that appears when you hover over the pill. And the choices are right here.

This is one of the very few things in Tableau that you just have to memorize. It looks a little bit strange because you see the same date parts duplicated. But the difference is this first set of choices are discrete, and the second set of choices are continuous.

I just wish they were color coded here. It’d be a little bit easier to figure out what I needed to do. But let’s say we wanted to get back to continuous month. Let’s say we forgot that shortcut, and we were making this sales line graph, and we just double-clicked order date. And we ended up here.

Not a big deal. We can still change it just by clicking in to the pill. And we’re looking for the second occurrence of the word month because that’ll get us back to continuous at a month date part. This first one would be month at a discrete level. So we’d actually only see 12 months.

If I choose month that’s continuous, we’re back to the first line graph that we built. And then just like with our bar chart or any other chart, you can now slice and dice this further by adding additional fields to the columns or rows shelf. For example, if I put category on to the columns shelf, we’ve now got a continuous sales by month trend per category.

That’s how to make a line graph in Tableau. This has been Ryan with Playfair Data TV – thanks for watching!