BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
MWAG
Calcite | Level 5

I would like to color the backround in the line chart of the last three years. 

 

chart.png

Any idea how this could be done?

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

You can achieve this using the custom graph builder. The end result will look like this

BrunoMueller_0-1698095111727.png

Basic steps for creating the custom graph

  • create a new custom graph
  • add a band plot to the graph
  • assign the right y axis to the band plot
  • uncheck all the right y axis elements (line, label, values, tick marks)
  • do no display any grid lines for this axis
  • add either a timeseries or a series plot
  • both plots will share the x axis
  • save 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.

View solution in original post

5 REPLIES 5
Joy_SAS
SAS Employee

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

ballardw
Super User

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.

BrunoMueller
SAS Super FREQ

You can achieve this using the custom graph builder. The end result will look like this

BrunoMueller_0-1698095111727.png

Basic steps for creating the custom graph

  • create a new custom graph
  • add a band plot to the graph
  • assign the right y axis to the band plot
  • uncheck all the right y axis elements (line, label, values, tick marks)
  • do no display any grid lines for this axis
  • add either a timeseries or a series plot
  • both plots will share the x axis
  • save 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.

MWAG
Calcite | Level 5

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.

yabwon
Onyx | Level 15

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:

yabwon_0-1698130431738.png

 

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Tips for filtering data sources in SAS Visual Analytics

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.

Discussion stats
  • 5 replies
  • 779 views
  • 0 likes
  • 5 in conversation