Skip to content
Tutorials Center
My learning

Topics

Lesson 80 of 86 ยท Projects

Project: Data Interpretation Dashboard

Build an HTML and JavaScript dashboard that draws a table, a bar chart and a pie chart from one dataset and asks data interpretation questions.

Data interpretation (DI) questions give you a table, a bar chart or a pie chart and ask for totals, percentages, ratios and growth rates. The maths is the same arithmetic you have already practiced; the new skill is reading each kind of display quickly and knowing what it shows well. A table gives exact numbers, a bar chart makes comparisons easy, and a pie chart shows each part's share of a whole.

In this project you will build a small dashboard that draws all three views from one dataset, and asks questions whose answers are calculated from that same dataset. Building it forces you to work out the formulas behind each chart, such as angles in a pie chart and bar heights, and it gives you an endless supply of practice that stays correct even if you change the numbers.

One dataset, three views

The most important design rule is a single source of truth. The numbers live in one JavaScript object. The table, the bar chart, the pie chart and the questions are all functions of that object. Change one number and every view and every answer updates.

flowchart TB
    D["One dataset: years x products"] --> T["Table: exact values and totals"]
    D --> B["Bar chart: compare across years"]
    D --> P["Pie chart: share of a year's total"]
    D --> Q["Questions: answers computed from the data"]

Every view and every answer is calculated from the same dataset.

The data is a made-up company's sales, in thousands of units, for four products over four years. Because it is just an object, you can replace it with any other data of the same shape: exam marks, rainfall, budgets.

The formulas behind the charts

  • Share of a whole. A product's share in a year is its value divided by that year's total, times 100.
  • Pie angle. A full circle is 360 degrees, so a slice's angle is share x 360. A 25% slice has 90 degrees. This is why DI questions with pie charts often give angles instead of percentages.
  • Bar height. If the tallest bar must fit in H pixels and the axis tops out at M, a value v gets a height of v / M x H. The axis maximum is rounded up to a tidy number, such as 250, so the ticks are easy to read.
  • Percentage growth. Growth = (new - old) / old x 100. Always divide by the old value, one of the most common slips in DI questions.

The script below calculates these for the same dataset as the dashboard, which makes it a handy way to check an answer by hand.

JS The maths behind the views

Press Run (or Ctrl + Enter) to see the console output here.

No output.

With this data the rounded shares happen to add up to exactly 100, but with other numbers they can add up to 99 or 101. That is rounding, not a mistake, so in a real DI question compute from the raw numbers and round only at the end.

The dashboard

Use the tabs to switch views, change the year to redraw the pie chart, and answer the questions at the bottom. The questions rotate through four templates (a total, a percentage share, a growth rate and a difference), and the answer for each is computed from the data. You get a worked solution after each check.

Data interpretation dashboard

How the dashboard works

  • Rendering is just string building from the dataset. Product names and numbers come from our own object, so inserting them with innerHTML is safe here. If data came from users or the network you would use textContent instead.
  • The bar chart finds the largest value, rounds it up to a multiple of 50 for the axis, and scales every bar by value / axis maximum. Grouping by year makes it easy to see each product's trend; grouping by product would make it easier to compare products within a year.
  • The pie chart walks around the circle. Each slice starts where the previous one ended and spans share x 360 degrees. The path uses an SVG arc; the large flag must be 1 when a slice covers more than half the circle, or the arc takes the short way round.
  • The questions use four templates and rotate through years and products with simple arithmetic on a counter. All answers are computed from DATA, so edit a number in the dataset and the model answers change too.

Choosing the right view

A good DI solver decides in seconds what each display is best for:

  • Table: exact figures, totals and ratios; use it when you need precision.
  • Bar chart: which is bigger, by how much, and trends over time; read the axis scale first, as it may not start at zero.
  • Pie chart: share of one total; remember that it shows proportions, not absolute amounts. Two pie charts of different totals cannot be compared slice by slice without the totals.

Read the title, the units and the axis before any question: a "thousand units" label hidden in the caption is where wrong answers start.

Ideas to extend it

  1. Add a line chart view using an SVG polyline through the yearly totals.
  2. Let the user paste their own numbers into a text area and parse them (comma-separated values) into the same dataset shape.
  3. Add a "mixed set" question that needs two views at once, such as "What was Phones' share in the year when total sales first crossed 400?"
  4. Link it with the Random Question Generator idea: generate a random dataset from a seed and ask questions about it.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. In the dataset, what were the total sales in 2023 (thousand units)?

    Phones 180 + Laptops 100 + Tablets 60 + Watches 40 = 380.
  2. 2. What percentage of 2022 sales (total 320) were Phones (150)? Nearest whole number.

    150 / 320 x 100 = 46.875, which rounds to 47%.
  3. 3. A slice of a pie chart is 25% of the total. What is its angle?

    Angle = share x 360 = 0.25 x 360 = 90 degrees.
  4. 4. Watches sales rose from 20 to 60 thousand units between 2021 and 2024. What is the percentage growth?

    Growth = (60 - 20) / 20 x 100 = 200%. Always divide by the old value (20), not the new one.
  5. 5. Why should every view and every question be generated from one dataset object?

    A single source of truth keeps views consistent and removes the risk of a chart and an answer using different numbers.

Summary

  • Keep the numbers in one object and compute the table, bar chart, pie chart and answers from it.
  • Pie angle = share x 360; bar height = value / axis maximum x plot height; growth = change / old value x 100.
  • Rounded percentages may add to 99 or 101; compute from raw numbers and round last.
  • Table for exact values, bar chart for comparison and trend, pie chart for share of one total.
  • Read the title, units and axis before answering any DI question.

Next: Project: Puzzle and Seating Solver, where you will write a brute-force solver for arrangement puzzles.