Showing markers on a series chart using the GTL

1k Views Asked by At

I'm trying to get markers to show up on my chart using the Graphics Template Language. I've tried adding the marker definitions to the style, to the seriesplot statement within a markerattrs= option statement, and also using discreteattrmaps for the chart group. I can't seem to get any of these approaches working.

Style definition:

proc template;
  define style excel; 
    parent=styles.htmlblue;
    class graph       / attrpriority='none';
    style graphdata1  / contrastColor=#416FA6;
    style graphdata2  / contrastColor=#A8423F;
    style graphdata3  / contrastColor=#86A44A;
    style graphdata4  / contrastColor=#8064A2;
    style graphdata5  / contrastColor=#DA8137;
    style graphdata6  / contrastColor=#D7E4BD;
    style graphdata7  / contrastColor=#FCD5B5;
    style graphdata8  / contrastColor=#8EA5CB;
    style graphdata9  / contrastColor=#E6B9B8;
    style graphdata10 / contrastColor=#CCC1DA;
  end; 

run; 

Template for the chart:

proc template;
  define statgraph excel_series_trended;
    dynamic _date _class _metric _title;
    begingraph;
       entrytitle halign=center _title;

      discreteattrmap name="symbols" / ignorecase=true ;
        value "IBM" / markerattrs=(color=blue symbol=diamondfilled) ;
        value other / markerattrs=(color=red  symbol=circlefilled) ; 
      enddiscreteattrmap ;

      discreteattrvar attrvar=groupmarkers var=stock attrmap="symbols" ;

       layout lattice / rowdatarange=data columndatarange=data rowgutter=0 columngutter=0;

          layout overlay / walldisplay=(fill) 
                           yaxisopts=( griddisplay=on gridattrs=(pattern=2 color=Cx999999) linearopts=(viewmin=0) )
                           xaxisopts=( type=discrete  );
             seriesplot x=_date y=_metric / group=_class markercolorgroup=_class name='series' groupdisplay=overlay connectorder=xaxis lineattrs=(pattern=solid thickness=3);
          endlayout;

          sidebar / align=bottom spacefill=false;
             discretelegend 'series' / opaque=true border=false halign=center valign=center displayclipped=true order=rowmajor;
          endsidebar;

       endlayout;

    endgraph;
  end;
run;

Render the chart using the sashelp.stocks dataset:

ods html style=excel;
ods graphics / antialias=on antialiasmax=999999;
proc sgrender data=sashelp.stocks template=excel_series_trended;
  where date between '01jan2005'd and '01jun2005'd;
  dynamic _date="date" _metric="high" _class="stock";
run;
2

There are 2 best solutions below

5
On BEST ANSWER

You need to do two things, presumably.

First, add display=(markers) to the seriesplot statement; that enables markers.

Second, add markersymbolgroup=groupmarkers to that same statement to enable the discrete attribute map to be used for markers, and change markercolorgroup to the same value. You cannot use a dynamic variable to define these, and shouldn't - you should use the discreteattrvar value.

Full code:

proc template;
  define statgraph excel_series_trended;
    dynamic _date _class _metric _title;
    begingraph;
       entrytitle halign=center _title;

      discreteattrmap name="symbols" / ignorecase=true ;
        value "IBM" / markerattrs=(color=blue symbol=diamondfilled) ;
        value other / markerattrs=(color=red  symbol=circlefilled) ; 
      enddiscreteattrmap ;

      discreteattrvar attrvar=groupmarkers var=stock attrmap="symbols" ;

       layout lattice / rowdatarange=data columndatarange=data rowgutter=0 columngutter=0;

          layout overlay / walldisplay=(fill) 
                           yaxisopts=( griddisplay=on gridattrs=(pattern=2 color=Cx999999) linearopts=(viewmin=0) )
                           xaxisopts=( type=discrete  );
             seriesplot x=_date y=_metric / group=_class name='series' 
                                            markersymbolgroup=groupmarkers markercolorgroup=groupmarkers
                                            groupdisplay=overlay connectorder=xaxis lineattrs=(pattern=solid thickness=3)
                                            display=(markers);
          endlayout;

          sidebar / align=bottom spacefill=false;
             discretelegend 'series' / opaque=true border=false halign=center valign=center displayclipped=true order=rowmajor;
          endsidebar;

       endlayout;

    endgraph;
  end;
run;
0
On

Although I've marked Joe's answer as accepted I ended up choosing a slightly different solution that was easier to maintain in my final project.

The key part of the syntax I was missing was the display=(markers) option on seriesplot (as Joe pointed out). Once that was added, I was able to control the marker symbol simply by specifying it in the style:

proc template;
  define style excel; 
    parent=styles.htmlblue;
    class graph       / attrpriority='none';
    style graphdata1  / contrastColor=#416FA6 markersymbol='circlefilled';
    style graphdata2  / contrastColor=#A8423F markersymbol='circlefilled';
    style graphdata3  / contrastColor=#86A44A markersymbol='circlefilled';
  end; 

run; 

Unfortunately the style does not support the markersize= option (despite what the documentation says). For that I ended up adding the markerattrs=(size=_markersize) option to the seriesplot statement. I made _markersize a dynamic value with a default of 0px, (ie. don't show markers). Now the template allows me to easily change the symbol, and or the size of the markers:

proc template;
  define statgraph excel_series_trended;
    dynamic _date _class _metric _title _markersize=0px;
    begingraph;
       entrytitle halign=center _title;

       layout lattice / rowdatarange=data columndatarange=data rowgutter=0 columngutter=0;

          layout overlay / walldisplay=(fill) 
                           yaxisopts=( griddisplay=on gridattrs=(pattern=2 color=Cx999999) linearopts=(viewmin=0) )
                           xaxisopts=( type=discrete  );
             seriesplot x=_date y=_metric / display=(markers) group=_class name='series' groupdisplay=overlay connectorder=xaxis 
                                            lineattrs=(pattern=solid thickness=3) 
                                            markerattrs=(size=_markersize)
                                            ;
          endlayout;

          sidebar / align=bottom spacefill=false;
             discretelegend 'series' / opaque=true border=false halign=center valign=center displayclipped=true order=rowmajor;
          endsidebar;

       endlayout;

    endgraph;
  end;
run;