我有一个数据集,用于计算每小时生产的托盘数量,例如
11/11/2010 22:00 --> 22
2010年11月11日 23:00 --> 12
2010年11月12日 00:00 --> 18
2010/11/12 01:00 --> 19
2010/11/12 03:00 --> 20
您可能会注意到,01:00 和 03:00 之间有一个间隙,因为该小时没有数据。该数据在 SSRS 2005 中使用带有时间尺度 x 轴的图表进行可视化。当图形类型为“柱形”时,完全没有问题,因为 02:00 可视化时没有 (0) 值,并且间隙在图形中清晰可见。当图形类型为“线”或“面积”时,02:00 也会在图形上可视化,但没有 0 值:01:00 和 03:00 的值之间有一条连接线。查看折线图时,人们可以得出结论,02:00 处有生产,但事实并非如此,它只是连接 01:00 的值与 03:00 的值的线。
面积图中相同数据的示例 (原始图像:http://img577.imageshack.us/img577/9616/area.jpg)
和柱形图 (原始图片:http://img577.imageshack.us/img577/7590/column.jpg)
应该解释这个问题。
有谁知道如何解决这个问题?谢谢你!
I have a dataset which counts the number of produced pallets per hour, eg
11/11/2010 22:00 --> 22
11/11/2010 23:00 --> 12
11/12/2010 00:00 --> 18
11/12/2010 01:00 --> 19
11/12/2010 03:00 --> 20
As you may notice, there is a gap between 01:00 and 03:00 since there is no data for that hour. This data gets visualised in SSRS 2005 using a graph with a time-scale x-axis. When the graph type is 'Column', there is no problem at all since 02:00 gets visualised with no (0) value and the gap is well visible in the graph. When the graph type is 'Line' or 'Area', 02:00 is visualised on the graph as well but with no 0 value: there is a connection line between the value of 01:00 and 03:00. When looking to the line graph, one could conclude that there was production at 02:00 but this is not true, it is just the line that connects the value of 01:00 with the value of 03:00.
Example of the same data in an Area graph (original image: http://img577.imageshack.us/img577/9616/area.jpg)
and a Column graph (original image: http://img577.imageshack.us/img577/7590/column.jpg)
should explain the problem.
Does anyone know how to resolve this problem? Thank you!
发布评论
评论(1)
也许,您现在已经找到了问题的答案。这是针对可能偶然发现这个问题的其他人的。仅当您使用
SQL Server 2005 或更高版本
作为报表的数据源时,此解决方案才适用。该示例使用通用表表达式 (CTE)
来实现问题中提到的所需结果。下面提到的示例使用SSRS 2005
和SQL Server 2008 R2
数据库。SQL Server 2005 或更高版本
支持 CTE。分步过程:
创建一个名为
dbo.TimeScaleData
的表,并使用问题中提供的数据进行填充。请参阅屏幕截图#1。 SQL 脚本部分下提供了表的创建脚本。创建一个 CTE,它将获取表
dbo.TimeScaleData
中的最小和最大日期值,并生成给定范围内每小时的所有时间值。然后在 CTE 和表 dbo.TimeScaleData 之间使用 OUTER APPLY 来获取数据。任何没有匹配记录的时间范围都将被分配值 0。请参阅屏幕截图 #2。该查询将在 SSRS 报告中用于创建数据集。查询在 SSRS DataSet Query 部分中提供。屏幕截图 #3 显示 CTE 查询用于创建报告数据集。屏幕截图 #4 - #7 显示如何配置图表控件以使用数据集。
屏幕截图 #8 显示针对 SQL Server 表中数据的报告输出。
希望有帮助。
SQL 脚本:
SSRS 数据集查询:
屏幕截图 #1:
屏幕截图 #2:
屏幕截图 #3:
屏幕截图#4:
屏幕截图 #5:
屏幕截图 #6:
屏幕截图 #7:
屏幕截图 #8:
Probably, you have found an answer to your question now. This is for others who might stumble upon this question. This solution is only applicable if you are using
SQL Server 2005 or above
as the data source for the reports. The example usesCommon Table Expressions (CTE)
to achieve the desired results mentioned in the question. The example mentioned below usesSSRS 2005
andSQL Server 2008 R2
database. CTEs are supported inSQL Server 2005 or above
.Step-by-step process:
Create a table named
dbo.TimeScaleData
and populate with the data provided in the question. Refer screenshot #1. Create scripts of the table is provided under SQL Scripts section.Create a CTE that will take the minimum and maximum date values in the table
dbo.TimeScaleData
and generate all the time values for every hour between the given range. Then useOUTER APPLY
between the CTE and the tabledbo.TimeScaleData
to fetch the data. Any time range that doesn't have a matching record will be assigned the value 0. Refer screenshot #2. This query will be used in the SSRS report to create the dataset. The query is provided SSRS DataSet Query section.Screenshot #3 shows that the CTE query is being used to create the report dataset. Screenshots #4 - #7 shows how the Chart control is configured to use the dataset.
Screenshot #8 shows the report output against the data in SQL Server table.
Hope that helps.
SQL Scripts:
SSRS DataSet Query:
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Screenshot #7:
Screenshot #8: