One of the most popular tools when creating data visualizations is an animated line chart that 'grows.' An advantage of using a line chart for this type of visualization is the ability to demonstrate how different data groupings grow and change over time.
SAS Visual Analytics report developers have long wanted to create these types charts to visualize time series data such as stock-market values over time. As of SAS Visual Analytics 8.3, report developers can! In this post, I will use a data trick similar to the one I previously demonstrated a previous post to create the type of growing animated line plot we are looking for:
Above, I've created an animated 'growing' line chart using data from the North Carolina Science Festival's Data on the Fly event. Data on the fly was an event in which presenters from SAS, the Department of Transportation and the NC Science Festival shared their excitement about analytics and aviation and instructed groups of high school students on how to construct Stratux aircraft monitoring devices. After building these Stratux devices, the students used them to collect ADSB data that was being transmitted by aircraft that are in the area. The resulting data the students collected during the event can be found in this Curriculum Pathways Data Depot resource. So how do we create the chart?
Initially, the Data on the Fly data set looks like this:
This data is perfectly suited to create an animated growing line chart due to the fact that the records collected by each aircraft manufacturer continues throughout the duration of the data set. Each observation in the data represents one, single successful record sent from each aircraft and received by the students' Stratux devices.
To create the animated 'growing' line plot, we will keep two columns from the original data:
We also need to create a 'Total' column and use it to determine the total number of records collected by each aircraft manufacturer. For simplicity, we'll focus on only one of the Stratux devices and only retain records that contain valid aircraft manufacturer values. Additionally, we'll create a new column (named 'Time') which rounds the TimeStamp variable to the nearest 15 minute interval.
The code blocks below will do this data preparation for us:
data start;
set dotf.data_on_fly;
Total = 1;
Time=intnx('minute15',timepart(TIMESTAMP),1,'b');
format Time Timeampm8.;
keep TimeStamp mfr_acft Total Time;
where ReceiverName = 'sierra' AND mfr_acft NOT IS MISSING;
run;
PROC SQL;
create table totals as select
mfr_acft as Manufacturer label="Aircraft Manufacturer",
Time,
sum(Total) AS Total_Records format=comma8. label="Total Records Collected By Stratux Device"
from start
group by mfr_acft, time;
QUIT;
Some records from the resulting data set "TOTALS" are show below:
Now for the data trick! In my previous post, I was able to make the bar charts 'stick' by using a basic do loop to loop though the data and create the "Animation_Date" variable. This was really easy because SAS Dates are simply a numeric counter that iterates though the days one record at a time. However in this data, the variable we need to source the "animation" variable from is not a day, but a TIME. MORE SO, it's a time based on 15-minute intervals. Fortunately support.sas.com has a fantastic example of how to loop though date/time intervals using the intck function.
Leveraging this example, we can customize it to work with our need to loop though the data in 15-minute intervals:
%macro time_loop(start,end);
%let start=%sysfunc(inputn(&start,NLTIMAP10.));
%let end=%sysfunc(inputn(&end,NLTIMAP10.));
%let dif=%sysfunc(intck(minute15,&start,&end));
data loop_times;
set totals;
%do i=0 %to &dif;
%let AT=%sysfunc(putn(%sysfunc(intnx(minute15,&start,&i,b)),NLTIMAP10.));
%put &AT;
Animation_Time=input("&AT",NLTIMAP10.);
format Animation_Time Timeampm8.;
output;
%end;
run;
%mend;
%time_loop(4:00:00 PM,8:00:00 PM);
After running our customized macro, we have the needed data structure to make the animated line plot 'grow,' where each 15- minute interval has the full range of time segments nested within it:
Just like in the bar chart example, the new variable, "Animation_time," is what can be used in the line plots animate role. In the example above, when the play button is pressed and the animation slider advances though the variable Animation_time (from 4pm through 8pm), the value of "4:00 PM - Airbus: 242" is retained though the entire animation!
Finally, we need to run a where clause to keep only the records where "Time" is less than or equal to "Animation_Time":
data DATA_ON_THE_FLY; set loop_times; where Time le Animation_Time; run;
Now that our new data structure has been built by the time based do-loop and where clause, we can feed our new data set into SAS Visual Analytics and assign the following roles:
Category: Time
Measure: Total Records Collected By Stratux Device
Group: Aircraft Manufacturer
Animation: Animation_Time
We now have the long-sought after growing animated line chart! In the example below, I added a filter to my line plot to only show three aircraft manufacturers.
This example was created in SAS Visual Analytics 8.3. Attached to this post is:
Import the data on your SAS Visual Analytics instance. Import the report via the "Import via GUI" section of these instructions.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.