FastReport中国社区FastReport联系电话 联系电话:023-68661681

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

来源:   发布时间:2019-09-18   浏览:4042次

分组报告是数据分析所必需的。但是当有大量数据并且不需要全部显示时,带有分组的常规报告变得麻烦且多余。您希望为此类案例找到通用解决方案吗?这里正好有一个。

带有下拉列表的报告本质上是一个包含分组数据的报告,但能够通过鼠标单击隐藏或显示组中的数据。它不仅非常方便,而且美观。毕竟,报告成为一个交互式对象。当用户可以参与信息显示时,用户会很高兴。

考虑如何制作此类报告的示例。首先,与Master-Detail主从报表一样(点击这里查看如何制作Master-Detail主从报表>>),我们需要一个包含链接表的数据源。假设我们有两个表:客户和订单。

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

一个客户可以做很多订单——一对多的关系。我们加上吧。单击Actions按钮,然后从下拉列表中选择New Relation ...

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

父表是主表,然后选择“customer”。子表分别是“orders”。在“customer”中有一个主键CustNo,在列表中选择它。在“orders”中有一个外键CustNo,也选择它。

结果,我们获得了连接:

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

现在让我们开始创建报告模板。添加一个频段“group header”。在它上面我们将放置链接中的字段:“orders.customer.Company”、“orders.customer.Addr1”、“orders.customer.Phone”、“orders.customer.Contact”。

除了这些字段之外,我们还要为此频段添加一个复选框控件。在CheckedSymbol属性中,选择Plus,然后选择UncheckedSymbol - Minus。

添加“orders”表中的字段:OrderNo、SaleDate、PaymentMethod、AmountPaid到“Data”频段。另外,为数据和字段标题添加标题区:

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

双击组标题“Headline”。选择要分组的字段:

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

现在选择我们之前添加的复选框。给它一个Hyperlink属性:

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

选择“Group Header”区域并为其创建BeforePrint事件处理程序:

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

 private void GroupHeader1_BeforePrint(object sender, EventArgs e)
 {
 string groupName = (String)Report.GetColumnValue("orders.customer.Company");
 // get the group name
 bool groupVisible = expandedGroups.Contains(groupName);
 // Check group visibility
 DataHeader1.Visible = groupVisible;
 Data1.Visible = groupVisible;// Set the visibility of data in accordance with the visibility of the group
 GroupFooter1.Visible = groupVisible;// Set the visibility of the basement of the group in accordance with the visibility of the group
 CheckBox1.Checked = !groupVisible;// Set the state of the flag depending on the visibility of the group
 }

还要向类添加扩展组列表:

private List expandedGroups = new List();

让我们回到我们的复选框。为此,创建一个Click事件处理程序:

private void CheckBox1_Click(object sender, EventArgs e)
{
string groupName = (sender as CheckBoxObject).Hyperlink.Value; // We get the name of the group from the hyperlink
if (expandedGroups.Contains(groupName)) // If the list of visible groups contains the selected group
expandedGroups.Remove(groupName); // Then remove the selected from the list of visible groups.
else
expandedGroups.Add(groupName); // Otherwise add the group to the list of visible
Report.Refresh(); // Update Report
}

以预览模式运行报告:

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力


现在点击任何加号:

如何制作Drill-Down向下钻取报表,为数据分析提供多种交互能力

当您单击减号时会分组折叠。大神们都表示同意,这样确实很方便。



产品介绍 | 下载试用 | 优惠活动 | 在线客服

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:FastReport控件中文网 [https://www.fastreportcn.com/]
本文地址:https://www.fastreportcn.com/post/2435.html

相关产品: FastReport.Net,


联系我们
  • 重庆总部 023-68661681
购买
  • sales@evget.com
合作
  • business@evget.com


在线
客服
微信
QQ 电话
023-68661681
返回
顶部