Bar Chart Racer
Author: Kevin Wayne (firstname.lastname@example.org).
Overview. Write a program to produce animated bar charts like the following one:
This animated bar chart visualizes the 10 most populous cities in the world, from 1500 to 2018. To generate this visualization, students will successively draw 519 individual bar charts (one per year of data), with a short pause between each drawing. Each bar chart contains bars for the 10 most populous cities in that year, sorted in descending order of population, and colored according to world region.
Learning objectives. By the end of this assignment, students should be able to
- Define a total order for a user-defined type.
- Sort an array/list of objects using the system sort.
- Read a text file one line at a time.
- Parse a line of text consisting of fields, separated by commas.
- Produce an animation by drawing a sequence of frames.
Niftiness. The assignment is nifty because it combines graphics and real-world data to create a captivating visualization. Animated bar charts spread virally over social media in 2019 because they are a surprisingly simple, yet powerful, way to tell a story about categorical data over time. We supply a variety of real-world data sets drawn from human geography, sports, entertainment, and business.
Data files. One of the principal contribution of this assignment is the data curation for several fascinating input files, including population by city or country; movies by gross revenue; global brands by valuation; European football clubs by Elo rating; and characters in Avenger's Endgame by screen time.
|input file||description||period||data source|
|cities.txt||most populous cities in the world||1500–2018||John Burn-Murdoch|
|countries.txt||most populous countries in the world||1950–2100||United Nations|
|cities-usa.txt||most populous cities in the U.S.||1790–2018||U.S. Census Bureau|
|brands.txt||most valuable brands in the world||2000–2018||Interbrand|
|movies.txt||highest-grossing movies in the U.S.||1982–2019||Box Office Mojo|
|baby-names.txt||most popular baby names in the U.S.||1880–2018||U.S. Social Security|
|football.txt||the best football clubs in Europe||1960–2019||clubelo.com|
|endgame.txt||characters in Endgame by screen time||Minute 1–170||Prashant|
|game-of-thrones.txt||characters in Game of Thrones||S01E01–S8E06||Jeffrey Lancaster|
- Assignment handout (as offered on Coursera, Computer Science: Programming with a Purpose).
- Assignment FAQ (as offered on Coursera, Computer Science: Programming with a Purpose).
- Data files (see above table).
- BarChartRacer.pdf. Slides about this assignment (Kevin's Nifty SIGCSE talk)
Sample executions. Here are some sample executions:
|Summary||Write a program to create an animated bar chart.|
|Audience||CS1. Our students are primarily scientists and engineers, not necessarily computer scientists.|
|Difficulty||This assignment is not difficult. It takes one week in the second half of a CS 1 course. The reference solution is approximately 100 lines of code.|
Here are the main topics that the assignment addresses:
Many interesting variations of this assignments are suitable for CS1 (or even CS2).
|Credits||This assignment was inspired by tweets from from Matt Navarra and John Burn-Murdoch in early 2019.|