reporting services - SSRS line graph: x-axis time-scale with gaps in data -
i have dataset counts 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 may notice, there gap between 01:00 , 03:00 since there no data hour. data gets visualised in ssrs 2005 using graph time-scale x-axis. when graph type 'column', there no problem @ since 02:00 gets visualised no (0) value , gap visible in graph. when graph type 'line' or 'area', 02:00 visualised on graph no 0 value: there connection line between value of 01:00 , 03:00. when looking line graph, 1 conclude there production @ 02:00 not true, line connects value of 01:00 value of 03:00.
example of same data in area graph (original image: http://img577.imageshack.us/img577/9616/area.jpg)
and column graph (original image: http://img577.imageshack.us/img577/7590/column.jpg)
should explain problem.
does know how resolve problem? thank you!
probably, have found answer question now. others might stumble upon question. solution applicable if using sql server 2005 or above
data source reports. example uses common table expressions (cte)
achieve desired results mentioned in question. example mentioned below uses ssrs 2005
, sql server 2008 r2
database. ctes supported in sql server 2005 or above
.
step-by-step process:
create table named
dbo.timescaledata
, populate data provided in question. refer screenshot #1. create scripts of table provided under sql scripts section.create cte take minimum , maximum date values in table
dbo.timescaledata
, generate time values every hour between given range. useouter apply
between cte , tabledbo.timescaledata
fetch data. time range doesn't have matching record assigned value 0. refer screenshot #2. query used in ssrs report create dataset. query provided ssrs dataset query section.screenshot #3 shows cte query being used create report dataset. screenshots #4 - #7 shows how chart control configured use dataset.
screenshot #8 shows report output against data in sql server table.
hope helps.
sql scripts:
create table [dbo].[timescaledata]( [id] [int] identity(1,1) not null, [datetimevalue] [datetime] null, [palletsproduced] [int] null, constraint [pk_timescaledata] primary key clustered ([id] asc)) on [primary] go
ssrs dataset query:
declare @startdatetime datetime; declare @enddatetime datetime; select @startdatetime = min(datetimevalue) , @enddatetime = max(datetimevalue) dbo.timescaledata; cte(datetimerange) ( select @startdatetime datetimerange union select dateadd(hour, 1, datetimerange) cte dateadd(hour, 1, datetimerange) <= @enddatetime ) select cte.datetimerange , coalesce(tsd.palletsproduced, 0) palletsproduced cte outer apply ( select palletsproduced dbo.timescaledata tsd tsd.datetimevalue = cte.datetimerange ) tsd;
screenshot #1:
screenshot #2:
screenshot #3:
screenshot #4:
screenshot #5:
screenshot #6:
screenshot #7:
screenshot #8:
Comments
Post a Comment