Getting Started with Pie Charts
This project will focus on drawing pie charts which are great for displaying categories of data.
We'll cover the following...
For this next project, we are going to draw a pie chart. Pie charts are another common type of chart to draw. They can show categories of data and how they are proportional to one another. The pie chart we will draw will show the estimated population by age as of 2015. The data was from the US census bureau for this example.
Currently, over 300 million people are living in the US. We can use a pie chart to display the total population. Each slice in a pie chart can display an age group to give the reader an idea of how many people are in each age group. Pie charts are great at showing demographics.
Reviewing starter project
Let’s get started. Here is the starter project we will be working on.
Let’s review the files together. Firstly, we have a standard HTML document. Nothing special is happening inside this file. We have the same setup we have been working with since the beginning. Up next, we have the CSS section. The CSS section contains a few styles but nothing new.
Let’s move onto the script section. A lot of it contains the same code we have been writing thus far. We are retrieving the files, setting the dimensions, and drawing the image. There is one thing to note about this code. We do not have accessor functions because we will not need them. Drawing pie charts takes a slightly different approach than most charts. We will go over the steps as we get to them.
Let’s take a peek inside the data file.
name,value<5,199120185-9,2050198210-14,2067978615-19,2135448120-24,2260423225-29,2169801030-34,2118363935-39,1985578240-44,2079612845-49,2137036850-54,2252549055-59,2100194760-64,1841568165-69,1454744670-74,1058772175-79,773012980-84,5811429≥85,5938752
We will be ...