Locked lesson.
About this lesson
There are many other basic charts you can use with openpyxl, such as bar charts, line charts, area charts, and scatter charts.
Exercise files
Download this lesson’s related exercise files.
30 - Intro To Charts and Graphs - Bar Charts, Line Charts, Area Charts, ScatterCharts.docx60.5 KB 30 - Intro To Charts and Graphs - Bar Charts, Line Charts, Area Charts, ScatterCharts SOLUTION.docx
56.7 KB
Quick reference
Intro To Charts and Graphs - Bar Charts, Line Charts, Area Charts, ScatterCharts
There are many other basic charts you can use with openpyxl, such as bar charts, line charts, area charts, and scatter charts.
When to use
Use this whenever you need a bar chart, line chart, area chart, or scatter chart.
Instructions
# Import the charts
from openpyxl.chart import Reference, Series, PieChart3D, BarChart3D, LineChart3D, AreaChart3D, ScatterChart
#Define our Chart instance
chart = PieChart3D() # or BarChart3D(), LineChart3D(), AreaChart3D(), ScatterChart()
The rest stays the same from the last video.
Hints & tips
- from openpyxl.chart import Reference, Series, PieChart3D, BarChart3D, LineChart, AreaChart3D, ScatterChart
- chart = PieChart3D() # or BarChart3D(), LineChart(), AreaChart3D(), ScatterChart()
- 00:04 Okay, in this video, I want to talk about some of the other charts and
- 00:07 graphs that you can use with openpyxl.
- 00:09 And we're not going to talk about these in great detail in this video,
- 00:11 we're going to talk about them in greater detail in future videos.
- 00:15 In this video, I just want to sort of let you know some of your options that you
- 00:18 have and we're going to run through them and look at them very quickly.
- 00:21 So let's start out by importing these things.
- 00:23 So we've imported PieChart and Reference.
- 00:26 We also want to import Series and this allows us to do series type math,
- 00:30 which some charts require, some don't.
- 00:33 But we'll go ahead and import it anyway.
- 00:35 Now we started out with PieChart, we can also do PieChart3D.
- 00:39 And a lot of these charts have 2D and 3D options and
- 00:42 we're going to look at the 3D options more often than just the 2D options.
- 00:47 Because they're more fun, but just sort of keep in mind,
- 00:50 a lot of these things have 2D options.
- 00:52 So let's go PieChart3D, let's go BarChart3D.
- 00:59 Let's go LineChart.
- 01:02 Let's go AreaChart3D.
- 01:05 And notice how these are capitalized, the A and the C, the L and the C, the B and
- 01:11 the C, the P and the C, the second word in the thing is always capitalized as well.
- 01:16 And finally, we also want to look at ScatterChart.
- 01:19 Now this one won't give us very useful information, but
- 01:22 I'll at least talk about it a little bit.
- 01:24 So, okay, let's just go through here and knock some of these out and
- 01:27 take a look at them.
- 01:28 So we come down here where we defined our chart in the last video.
- 01:33 Let's just pop in PieChart3D instead of the regular PieChart, and
- 01:38 everything else from this code is from our last video.
- 01:41 So okay, let's go ahead and save this and run it.
- 01:44 Let's go python format.py.
- 01:47 And then we can come over here and open our company_salaries2 file and
- 01:51 we see this 3D pie chart much more interesting than the regular 2D pie chart
- 01:55 that we looked at in the last video.
- 01:57 But sometimes 2D is more appropriate for presentation and 3D, but
- 02:01 you at least you have those different options with openpyxl.
- 02:05 So that's the 3D pie chart, pretty cool.
- 02:07 Let's go ahead and close this, and
- 02:09 let's run through the next one which was BarChart3D.
- 02:13 So I'll just paste this in here and let's go ahead and save this.
- 02:16 And let's run this guy.
- 02:18 Okay, now we can open this.
- 02:21 And again, this isn't that interesting.
- 02:23 It just sort of shows you what these look like.
- 02:25 We're not going to get into the data of each of these at all in this video.
- 02:28 I just want to give you a quick broad overview of some of the different main
- 02:31 charts and graphs that you can work with.
- 02:33 So bar chart looks pretty cool, right?
- 02:36 So that's the bar chart, let's go ahead and close this.
- 02:39 Next, we have the line chart.
- 02:43 Pop this one in here, save it, run it, okay?
- 02:50 And if we open our spreadsheet again, we get a basic line chart.
- 02:54 I'm not sure if this one has a 3D one or not, let's take a look real quick.
- 02:57 Let's come back over here and let's try LinChart3D.
- 03:03 Let me just pop that on there.
- 03:05 Like I said, I don't know if this will work or not.
- 03:07 So let's save this and run it, no error.
- 03:11 So fingers crossed, let's open this guy.
- 03:14 Okay, so yeah, we get a 3D looking line chart.
- 03:17 That's kind of cool, right?
- 03:19 So that's that one.
- 03:21 See what else do we have?
- 03:23 We have an area chart 3D.
- 03:26 If we pop this guy in, save this, run it again.
- 03:32 Open our spreadsheet.
- 03:34 I get this area chart 3D.
- 03:36 That's kind of cool.
- 03:38 If you're interested in what this looks like without 3D,
- 03:41 we can always just take off the 3D part here, right?
- 03:46 Sort of how that works, save this, run it.
- 03:50 Open up our spreadsheet, and we get just a basic area chart, right?
- 03:54 That's kind of cool.
- 03:56 And finally, we have the scatter chart.
- 03:58 Now this one isn't going to look very good or won't look good at all with our current
- 04:03 data because we don't have enough data for a good scatter chart.
- 04:06 But if you wanted to, we could run it anyway.
- 04:09 It's not going to tell us anything.
- 04:10 But we can open this.
- 04:14 And we get the thing but there's not really any scattered data here,
- 04:18 we really need more than just one set of data points.
- 04:21 We need at least two or three to get a good scatterplot.
- 04:24 But you get the idea.
- 04:26 And if your data requires a scatterplot, and you know if it does or not,
- 04:30 this is how you do it.
- 04:31 So okay, those are the sort of main charts and graphs that come with openpyxl.
- 04:36 And there are a lot of different sort of a more advanced charts and
- 04:40 graphs that you can work with.
- 04:42 Radar charts, donut charts, surface charts.
- 04:45 You can combine different charts together.
- 04:48 There's all kinds of cool stuff.
- 04:49 And we're going to look at all of those in the coming videos.
- 04:52 In the next video, we're going to start diving in to these charts we just looked
- 04:56 at but in more detail.
- 04:57 So in the next video, I think we'll look at bar charts.
Lesson notes are only available for subscribers.