1

我正在尝试使用图形模板语言让标记显示在我的图表上。我尝试将标记定义添加到样式中,添加到markerattrs=选项语句中的 seriesplot 语句中,并且还对图表组使用离散属性映射。我似乎无法使这些方法中的任何一种起作用。

风格定义:

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; 

图表模板:

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;

使用数据集渲染图表sashelp.stocks

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;
4

2 回答 2

1

你需要做两件事,大概。

首先,添加display=(markers)到 seriesplot 语句;启用标记。

其次,添加markersymbolgroup=groupmarkers到相同的语句以使离散属性映射能够用于标记,并更改markercolorgroup为相同的值。您不能使用动态变量来定义这些,也不应该 - 您应该使用离散属性值。

完整代码:

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;
于 2017-01-10T21:36:03.097 回答
1

尽管我已将 Joe 的答案标记为已接受,但我最终选择了一个稍微不同的解决方案,该解决方案在我的最终项目中更易于维护。

我缺少的语法的关键部分是display=(markers)seriesplot 上的选项(正如乔指出的那样)。添加后,我可以简单地通过在样式中指定它来控制标记符号:

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; 

不幸的是,该样式支持该markersize=选项(尽管文档中有说明)。为此,我最终将markerattrs=(size=_markersize)选项添加到seriesplot语句中。我创建_markersize了一个默认值为 , 的动态值0px(即不显示标记)。现在模板允许我轻松更改符号和/或标记的大小:

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;
于 2017-01-10T22:33:49.823 回答