赵翔鹏的Blog Xiangpeng's Thinkpad

30十二/082

SQL Server 2008 Reporting Service使用技巧

SSRS用来做报表很方便,据说比Crystal Reports好用。简单的说,你的报表数据来自SQL语句,然后就可以在类似Excel的环境中画图了。

说是这么说,实际做起来还是会遇到很多小麻烦。下面是总结的一些技巧:

  1. 改变图表上字体大小(如X轴、Y轴上的数字):

    先把LabelsAutoFitDisabled属性设为True ,然后再设置字体大小

  2. Data Label显示设置:

    在Series的SmartLabels里面有一些有用的选项。AllowOutsidePlotArea设为True比较好。

  3. 自定义Legend标题:

    要右键选Series的属性,不是Legend的属性

  4. Pie chart显示百分比:

    在Report properties - code中加入如下代码:

    Public Function GetLabel(ByVal currentValue As Integer, ByVal totalValue As Integer) As String

    If currentValue / totalValue < 0 Then '表示百分比小于1的不显示出来

    Return " "

    Else

    Return Format(currentValue / totalValue, "P1")

    End If

    End Function

    然后设置data label表达式:=Code.GetLabel(Count(Fields!IssueID.Value), Count(Fields!IssueID.Value, "Issues"))

  5. Pie chart排序

    右键点一个Category,在Category Group Properties中设置Sort表达式即可

    clip_image001

  6. 在Pie chart饼图外侧显示DataLabel:

    设置Series的CustomAttributes,PieLabelStyle=Outside

    clip_image002

    注意:参考AdventureWorks示例,有一个很好的饼图。(google上搜到的都是过时的东西)

  7. Asp.net中使用ReportViewer控件:

    必须在IIS的Handler Mappings中新建一个Managed Handler才能正常显示。 可以google搜索Reserved.ReportViewerWebControl.axd。

    clip_image003

    clip_image004

    另一个解决方法:据说配置下web.config文件也可以搞定:

    <httpHandlers>

        <add path="Reserved.ReportViewerWebControl.axd" verb="*"

             type="Microsoft.Reporting.WebForms.HttpHandler,

                   Microsoft.ReportViewer.WebForms,

                   Version=8.0.0.0, Culture=neutral,

                   PublicKeyToken=?????????????"

             validate="false" />

    </httpHandlers>

    http://www.knowsky.com/340782.html

  8. ReportViewer控件:

    可以设置ZoomMode属性为PageWidth,这样可以自动放缩。

    图表放大时会失真,因为不是矢量图。建议把原始报表拉大一些,在页面中留一个小点的空,默认ZoomMode=PageWidth,用户选择100%就可以放大。

    所有的toolbar按钮都可以选择显示或关闭,设置ShowXXX属性即可。

  9. 其他:

    对报表修改之后要及时Deploy,才能看到效果。可以在VS的configuration manager里面设置,debug时自动deploy,比较方便。这个默认是没有打开的,如下图所示,建议把Deploy的对勾打上。

    clip_image005

标签: 发表评论
评论 (2) 引用 (0)
  1. 谢谢分享。

    Sql Server 那么大,想掌握其方方面面真得很难。像我对Reporting Services 就知道地不多。

  2. @季庄新闻

    最近发现analysis service也很强,聚类分类都能干,又惊讶了一下。

    不过,虽然数据库有很多辅助功能,核心的东西还是离不开人去调优啊:)


Leave a comment

(required)

还没有引用.