Dear all,
I have a simple subgrouped vbar chart with proc gchart. I's like to do a drill down when the user clicks on one value of the x axis (not a click an one bar). Is that possible?
I tried to change the values of the x axis by putting an html link around it like this:
data work.for_graph;
set work.mydata;
xaxis_value = cats("<a href='http://www.sas.de'>",myValue,"</a>");
run;
But SAS then prints the whole string from above as value under the x axis. A click has no effect.
Best regards
Eva
There's no built-in feature in gchart to do this, but you can suppress the default bar midpoint text labels, and then annotate them, and have html drilldown for the annotated text. Here's an example:
%let name=anno_xaxis;
filename odsout '.';
/*
Suppress the usual midpoint axis text values,
and then annotate your own with html drilldown.
*/
data mydata;
format population comma12.0;
input st $ 1-2 population;
year=2000;
datalines;
VA 7078515
NC 8049313
SC 4012012
GA 8186453
FL 15982378
;
run;
data myanno; set mydata;
length html $500 text $20;
xsys='2'; ysys='1';
function='label';
style='albany amt';
position='5';
midpoint=st;
y=-3;
when='a';
text=trim(left(st));
html='title='||quote(
'State: '|| trim(left(st)) ||'0D'x||
'Population: '|| trim(left(put(population,comma12.0)))
)||
' href="http://www.state.'||trim(left(lowcase(st)))||'.us"';
run;
GOPTIONS DEVICE=gif;
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm"
(title="GCHART w/ GIF ODS HTML Drilldown")
style=sasweb;
goptions noborder gunit=pct htitle=6 htext=3.5;
axis1 label=none value=(color=white);
axis2 label=none order=(0 to 20000000 by 5000000) minor=none offset=(0,0);
pattern v=solid color=cx43a2ca;
title1 "Year 2000 U.S. Census Population";
title2 color=gray "GCHART w/ GIF ODS HTML Drilldown";
footnote color=gray "(text annotated as bar labels has drilldown)";
proc gchart data=mydata anno=myanno;
vbar st / discrete
type=sum sumvar=population
ascending
width=8
maxis=axis1
raxis=axis2
autoref cref=gray
clipref
coutline=black
des='' name="&name" ;
run;
quit;
ODS HTML CLOSE;
ODS LISTING;
There's no built-in feature in gchart to do this, but you can suppress the default bar midpoint text labels, and then annotate them, and have html drilldown for the annotated text. Here's an example:
%let name=anno_xaxis;
filename odsout '.';
/*
Suppress the usual midpoint axis text values,
and then annotate your own with html drilldown.
*/
data mydata;
format population comma12.0;
input st $ 1-2 population;
year=2000;
datalines;
VA 7078515
NC 8049313
SC 4012012
GA 8186453
FL 15982378
;
run;
data myanno; set mydata;
length html $500 text $20;
xsys='2'; ysys='1';
function='label';
style='albany amt';
position='5';
midpoint=st;
y=-3;
when='a';
text=trim(left(st));
html='title='||quote(
'State: '|| trim(left(st)) ||'0D'x||
'Population: '|| trim(left(put(population,comma12.0)))
)||
' href="http://www.state.'||trim(left(lowcase(st)))||'.us"';
run;
GOPTIONS DEVICE=gif;
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm"
(title="GCHART w/ GIF ODS HTML Drilldown")
style=sasweb;
goptions noborder gunit=pct htitle=6 htext=3.5;
axis1 label=none value=(color=white);
axis2 label=none order=(0 to 20000000 by 5000000) minor=none offset=(0,0);
pattern v=solid color=cx43a2ca;
title1 "Year 2000 U.S. Census Population";
title2 color=gray "GCHART w/ GIF ODS HTML Drilldown";
footnote color=gray "(text annotated as bar labels has drilldown)";
proc gchart data=mydata anno=myanno;
vbar st / discrete
type=sum sumvar=population
ascending
width=8
maxis=axis1
raxis=axis2
autoref cref=gray
clipref
coutline=black
des='' name="&name" ;
run;
quit;
ODS HTML CLOSE;
ODS LISTING;
I don't know annotate yet. But it seems worth learning.What you gave me as an example is exactly what I need. I guess I can use the html= option as addition to the above example? Because my customer wants to be able to click on the bar and the xaxis value (and also in a subgrouped bar chart by the way where clicking on a subgroup versus clicking on the value of the x axis makes sense in that I give a different target site depending on whether the user clicks on the subgroup or the xaxis value).
Yep - exactly! You can use both at the same time ... gchart's html= option to control the drilldown for the bar segments, and the html variable in the annotate data set to control the annotated bar midpoint labels (for your drilldown for the whole bar).
Great! Many thanx for your help.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.