Locked lesson.
About this lesson
In this lesson, we'll discuss how to add 2D and 3D Area Charts to your spreadsheet.
Exercise files
Download this lesson’s related exercise files.
32 - Area Charts - 2D and 3D.docx60.5 KB 32 - Area Charts - 2D and 3D SOLUTION.docx
56.7 KB
Quick reference
Area Charts - 2D and 3D
In this video we'll look at Area Charts in a little more detail.
When to use
Use this whenever you need an Area Chart in your spreadsheet.
Instructions
# Import the charts
from openpyxl.chart import Reference, Series, AreaChart, AreaChart3D
# Create a Chart instance
chart = AreaChart()
To stack more data, you don't need to change any settings, just add your data.
# Remove Legend
chart.legend = None
All the rest of the code is the same from the last couple of videos.
Hints & tips
- chart = AreaChart()
- chart.legend = None
- 00:04 Okay, in this video I want to look at AreaChart in a little more detail.
- 00:07 So I've defined our chart as AreaChart, make sure you have AreaChart up here.
- 00:11 And we're also going to look in this video at AreaChart3D.
- 00:14 So I'll just put the back end as well, remember we took this out a while back,
- 00:19 and yes, AreaChart and AreaChart3D.
- 00:22 And there's not a whole lot different between the AreaChart and the BarChart.
- 00:27 So most of the things that we did with the AreaChart in the last video,
- 00:30 we're still work with the AreaChart in this video.
- 00:33 So, for instance, we can set the y_axis and the x_axis.
- 00:37 We could do the chart.style, we can't really do the chart.shape.
- 00:40 This is just going to be a line anyway, so we'll comment this out.
- 00:44 And let's come up with this comment out of this chart.style with this number.
- 00:48 Since there's too many numbers to go through all of them,
- 00:50 you can look at those different chart.styles if you want.
- 00:53 But we're just going to take the default, so I'll comment that out.
- 00:57 So let's just save this and run it just to take a quick look at our chart here.
- 01:02 So let's run this guy, and open our company salaries to file again.
- 01:07 And we have this basic AreaChart, right?
- 01:11 So remember in the last video, we added some new data, and we stacked or
- 01:15 things you could do that same thing here with an AreaChart.
- 01:18 And you don't even have to sort of define the stacking like we did in the last few
- 01:23 with the bar charts.
- 01:24 Let's close this and see what I mean.
- 01:26 Let's open up our company_salaries file, and up here I'm going to put year 2 for
- 01:30 salaries, and let's change a couple of these.
- 01:33 Let's add stuff, make it bigger so
- 01:36 the data is a little more consistent.
- 01:40 Okay, so that looks good.
- 01:41 Let's go ahead and save this.
- 01:43 And now if we run this file again, after first coming up to our data and
- 01:47 defining that we want to include that other row or that other column.
- 01:51 So let's go max _col=3, so remember we started with column 2.
- 01:58 We also want to add column 3, so let's save this and run it, and
- 02:01 see what this looks like.
- 02:04 So company_salaries2, and
- 02:06 you can see we get AreaChart with two different sets of data, right?
- 02:10 In this red one is sort of overpowering the blue one because of the data that
- 02:15 we used, but you can see how that works.
- 02:18 So that's sort of interesting, right?
- 02:20 You can also do the same thing with 3D BarChart, and
- 02:23 it may be it's probably a little better to do it with the 3D BarChar.
- 02:26 Because with here, like I said, this red is overpowering the blue, so
- 02:30 we can't really see the blue stuff behind there.
- 02:33 So let's close this and change this back to let's see AreaChar3D.
- 02:41 So just making that change alone, running this again,
- 02:45 we'll see that this becomes a little bit more usable as data, right?
- 02:50 So because we can see the blue now, that was behind this red, so very interesting.
- 02:55 One other thing I'll mention while we're talking about these is this legend here.
- 03:00 We have the salaries in the year which we defined with our column heads, but
- 03:05 we can get rid of that if we want.
- 03:07 Because really, it's right here year 2 and salaries, year 2 and
- 03:11 salaries sort of redundant to have it both.
- 03:14 So it's really easy to do that we could just head back over to our code.
- 03:18 And just down here where we're defining charter type things.
- 03:20 We can go chart.legend = None.
- 03:24 And you can do this for all the graphs, right?
- 03:26 So let's save this, run this guy again, open it up.
- 03:32 And now our legend is gone, and it just has the labels as it did earlier.
- 03:38 So whatever your style is, whichever you prefer, that's fine.
- 03:43 And again,
- 03:43 notice our our graph is right up against here because we added this column.
- 03:47 Remember, before we put a space here, so you might want to change that as well.
- 03:52 Oops, you can resize very interesting.
- 03:56 So, okay, so that's really the only big difference between AreaCharts and
- 04:01 BarCharts.
- 04:02 Not a whole lot to talk about, but
- 04:04 some interesting things as far as the stacking goes, and that could be useful.
- 04:08 So that's all for this video.
- 04:09 In the next video, we'll look at radar charts.
Lesson notes are only available for subscribers.