I would like to color the backround in the line chart of the last three years.
Any idea how this could be done?
You can achieve this using the custom graph builder. The end result will look like this
Basic steps for creating the custom graph
In your report, go to the objects pane and use the 3 vertical dots icon to import the new custom graph and add the custom graph to your report.
Create two calculated data items for the band plot part of the custom graph, based on what timeframe should be colored assign 0 to the band plot lower limit and a 1 to the band plot upper limit. For these two calculated items assign an aggregation of either min or max.
A sample expression for the lower limit might look like this:
if someDateYear >= todayYear -1 return 0 else .
someDateYear is the year of the date used for the x axis and todayYear is the year of "today", both are calculated data items.
Give it a try.
Hi @MWAG,
I checked with the development team. Unfortunately, there isn't a way to do this with display rules in the current or previous releases of SAS Visual Analytics.
-Joy
I don't use Viya or Visual Analytics so this is guess of something that might be possible. If you can create a Polygon, either as a plot or annotate data you could provide a definition that corresponds to coordinates in you graph for that area. This would require you to set specific coordinates for each corner of the area manually so "last 3 years" is going to require you to calculate the first year, the last year to provide those values a x coordinate and the corresponding y value (zeros are usually easy ).
Overlay the series graph(s) over the polygon.
Maybe as I said.
You can achieve this using the custom graph builder. The end result will look like this
Basic steps for creating the custom graph
In your report, go to the objects pane and use the 3 vertical dots icon to import the new custom graph and add the custom graph to your report.
Create two calculated data items for the band plot part of the custom graph, based on what timeframe should be colored assign 0 to the band plot lower limit and a 1 to the band plot upper limit. For these two calculated items assign an aggregation of either min or max.
A sample expression for the lower limit might look like this:
if someDateYear >= todayYear -1 return 0 else .
someDateYear is the year of the date used for the x axis and todayYear is the year of "today", both are calculated data items.
Give it a try.
Thank you very much. That seems like a working solution. Unfortunately I do not have the rights for the graph builder. But in theory and as I can se within your example the solution works.
Hi,
you already have an answer but here is a "polygon" approach:
data have;
do x = 1 to 10;
Y = 0.5 * X + 1 + RANNOR(123);
output;
end;
run;
data polydata; /* create polygon data */
input IDp :$ Xp Yp;
datalines;
1 6 0
1 10 0
1 10 10
1 6 10
;
run;
data toPlot; /* combine plot data and polygon data*/
set have polydata;
run;
PROC SGPLOT data = toPlot;
polygon X=xp Y=yp id=idp /
fill
nooutline
fillattrs=(color=green transparency=0.6) /* set polygon's transparency and colour */
;
series x=x y=y;
run;
Result:
Bart
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!
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.