Exercise 7: Building a Bar-Line Combo Chart with Two Value Axes

COVE Data Definition Exercises

Learning Objectives

This exercise demonstrates the power of the combo chart, which allows you to specify a visual style for each data series.  It also supports two value axes so that you can show correlation (or lack of correlation) between different types of data series. This exercise also introduces date configuration for the date/category axis.

If you completed the earlier charting exercises in this series, you probably feel fairly comfortable with cartesian charts by now. So this exercise encourages you to work on your own but provides a checklist of configuration settings for each panel just in case you can’t find what you’re looking for.

This exercise supports the concepts presented in Data Visualization: Presenting Multiple Metrics (from a Single Data Source), which is a supplement to Defining Data for Visualization.  We recommend these documents and Exercises 1 through 3 in this series as prerequisites to this exercise.

Source Data

The following Excel screenshot shows the complete source data. To see the data file, click the link below the image.

Screenshot of source data for exercise 7

Download source file [XLS – 232 B]

Visualization You’re Building

This combo chart has two data series:  Outreach Costs is represented by a bar and New Participants is represented by a line.  Note the following:

  • The date/category axis goes only to May 2022, whereas the source data goes to September.
  • The date display format differs from the source format.
  • The two series require different numeric formats for optimal display.  (Outreach Costs have a $ prefix.)
  • The values for Outreach Costs are abbreviated (with “K” for 1,000).

Step-by-Step Instructions

Create the Content Item

  1. From the WCMS content (folder) browser, select New Content Item, and when prompted for the content type, select Data Visualization.
  2. Click the button Open Visualization Editor. 
  3. On the Choose Visualization Type tab, select Bar. (At the time of this document’s creation, the option for Combo Chart does not exist as an option on this tab.  When you configure the chart, you must change the Chart Type to Combo in the General tab.)

Import the Data

Before following the instructions below, take a look at the source data and the chart you’re building above.  Based on your observations, see if you can determine the answers to the key questions on the Import Data tab:  What is the orientation of the data?  Are there multiple data series?  Do the series values span multiple rows?

  1. In the Import Data tab, select Load from URL and then copy and paste the following URL:
    https://wwwdev.cdc.gov/wcms/4.0/cdc-wp/data-presentation/data/exercise-data/bar-line-combo-2-value-axes.csv
  2. Click Load.
  3. Select Vertical for the Orientation.
  4. When asked whether there are multiple series, select Yes.
  5. When asked whether the series span multiple rows, select Single Row.
  6. Click Configure your visualization.

Configure the General Panel

  1. Set the Chart Type to Combo.
  2. Set the Title and other text as you like.

Set Up the Data Series

  1. Add two series:  New Participants and Outreach Costs.
  2. For New Participants, click the right-arrow button to display the series drop-down menu. (The button is located to the right of the “Remove” option.)
  3. From the drop-down menu for New Participants, select Line as the Series Type, Right Axis and the Series Axis, and CurveLinear as the Series Line Type.  (Leave Show in Tooltip selected.)
  4. For Outreach Costs, you can leave the default settings (but confirm that the Series Type is Bar).

Set Up the Date/Category Axis

  1. The Data Type for this exercise is Date (Linear Scale), and the Data Key is the Date column.
  2. Based on the source data, set the Date Parse Format to %m/%d/%Y.
  3. Try a couple of display formats: To display the dates with a two-digit year, set the Axis Date Display Format to %m/%d/%y. (In short, change the “%Y” to “%y”.)
  4. Click I’m Done in the preview area to see your chart.  Note the dates along the date/category axis.
  5. To display the dates in the format shown in the exercise example: set the Axis Date Display Format to %b %Y.  The “%b” indicates an abbreviated month. (For more information on date formats, see this D3 resource.  A link is also provided in the COVE editor UI, just above the date parse and display fields.)
  6. Check Limit by Start and/or End Dates and then set the End Date to 5/15/2022.

Fine-Tune the Visualization

Compare your chart to the example at the top of the page and see if you can fine-tune it on your own.  In case you need some help, here are the settings to focus on:

  • For the Left Value Axis, add a Label and check the following:  Add Commas and Abbreviate Axis Values.  Also increase the Left Axis Max Value to 500000.  Set the Size (Width) to improve the label positioning.
  • For the Right Value Axis, add a Label and increase the Right Axis Max Value to 160.
  • For the Date/Category Axis, set the Number of Ticks to 5.
  • In the Visual panel, set the Font Size to Small.
  • For the Data Table, don’t forget to set an Index Column Header.