4.5.7 Visualize Data in an Area Chart

An area chart uses lines to connect the data points and fills the area below these lines to the x-axis. Each data series contributes to the formation of a distinct shaded region. This emphasizes its contribution to the overall trend. As the data points fluctuate, the shaded areas expand or contract.

When to use this chart: Use this chart to visualize trends, changes, and relationships in data over a continuous period.
Dataset: SH.SALES table in the SH schema.
To visualize data in an area chart:
  1. In another %sql paragraph, run the following script:
    SELECT
          TIME_ID,
          -- Use MAX(TOTAL_SOLD) to handle cases with duplicate TIME_ID and CHANNEL_ID
          MAX(CASE WHEN CHANNEL_ID = 2 THEN TOTAL_SOLD ELSE NULL END) AS Channel_2,
          MAX(CASE WHEN CHANNEL_ID = 4 THEN TOTAL_SOLD ELSE NULL END) AS Channel_4,
          MAX(CASE WHEN CHANNEL_ID = 3 THEN TOTAL_SOLD ELSE NULL END) AS Channel_3,
          MAX(CASE WHEN CHANNEL_ID = 9 THEN TOTAL_SOLD ELSE NULL END) AS Channel_9
    FROM (SELECT TIME_ID, CHANNEL_ID, sum(AMOUNT_SOLD) TOTAL_SOLD
      FROM SH.SALES
          WHERE TIME_ID >= TO_DATE('2001-09-01', 'YYYY-MM-DD')
          GROUP BY TIME_ID, CHANNEL_ID
          ORDER BY TIME_ID)
    GROUP BY TIME_ID
    ORDER BY TIME_ID
    This script groups the data by TIME_ID and CHANNEL_ID. It presents the data from 2001-09-01 and later. It shows the value for TOTAL_SOLD for each of the four channels grouped by CHANNEL_2, CHANNEL_3, CHANNEL_4 and CHANNEL_9.
  2. The data from the SALES table is now presented for the following columns—TIME_ID, CHANNEL_2, CHANNEL_3, CHANNEL_4 and CHANNEL_9.

    Figure 4-32 SALES table showing specific columns


    SALES table showing the columns TIME_ID, CHANNEL_2, CHANNEL_3, CHANNEL_4 and CHANNEL_9.

  3. Now, click on the the area chart icon Area chart icon in the tool bar to visualize the data in an area chart.

    Figure 4-33 Area Chart showing the sum for CHANNEL_2


    Area Chart showing the sum for CHANNEL_2

  4. Click on the Settings icon to open the Settings dialog. Under Setup:
    • Series to Show: Click to add CHANNEL_3, CHANNEL_4 and CHANNEL_9.
    • Group By: Retain the default, that is, TIME_ID.
    • Aggregate Duplicates: Retain the default, that is, SUM.
  5. Click Customization and under Visualization, click Stacked. The area chart is now presented as shown in the screenshot.

    Figure 4-34 Stacked Area Chart showing the sum for CHANNEL_3, CHANNEL_4 and CHANNEL_9


    Stacked Area Chart showing the sum for CHANNEL_3, CHANNEL_4 and CHANNEL_9

This completes the task of visualizaing your data in an area chart.