Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在动态加载的数据中缺少日期时,是否在ZingChart中设置图表间隙?_Sql Server_Coldfusion_Zingchart_Cfchart_Coldfusion 2016 - Fatal编程技术网

Sql server 在动态加载的数据中缺少日期时,是否在ZingChart中设置图表间隙?

Sql server 在动态加载的数据中缺少日期时,是否在ZingChart中设置图表间隙?,sql-server,coldfusion,zingchart,cfchart,coldfusion-2016,Sql Server,Coldfusion,Zingchart,Cfchart,Coldfusion 2016,我一直在使用ColdFusion 2016和ZingCharts(捆绑)使用SQL Server动态创建图表,时间序列在X轴上。当有时间间隔时,我希望折线图也显示一个间隔,但是折线是连续的,并连续绘制每个数据点 从图中可以看出,10月29日和3月29日之间没有“间隔”,数据只是一起运行: 我的数据通常以15分钟为增量,但在时间序列和数据中存在间隔的时间段(天或月)。我联系了ZingCharts,询问是否有某种样式标记可以控制日期是连续显示还是有间隙显示,而没有。这是必须在数据层面进行操作的东西

我一直在使用ColdFusion 2016和ZingCharts(捆绑)使用SQL Server动态创建图表,时间序列在X轴上。当有时间间隔时,我希望折线图也显示一个间隔,但是折线是连续的,并连续绘制每个数据点

从图中可以看出,10月29日和3月29日之间没有“间隔”,数据只是一起运行:

我的数据通常以15分钟为增量,但在时间序列和数据中存在间隔的时间段(天或月)。我联系了ZingCharts,询问是否有某种样式标记可以控制日期是连续显示还是有间隙显示,而没有。这是必须在数据层面进行操作的东西。如果我的数据是硬编码的,我将不得不添加空值,以便图表可以绘制时间序列中的间隔,但我的图表是动态的(用户可以选择任意数量的7个参数,以添加到他们选择的日期范围的图表中)。我已经找到了关于如何解决硬编码数据的信息,但我正在寻找动态加载数据/系列的解决方案。我还找到了有关XML文件的不推荐使用的coldfusion标记的信息,
isInterpolated=“false”
,但这不再是一个选项

我的问题是解决这个问题的最好方法是什么?我想知道是否还有另一种方法我没有想到?谢谢你的帮助,我对这一切都很陌生


更新:这是数据的当前查询,有点复杂。它根据选择的参数数量(7个可用参数)和日期范围内的天数来提取“n”行:

SELECT
distinct 
 datepart(year, t.sample_date) as [year]
,datepart(month, t.sample_date) as [month]
,datepart(day, t.sample_date) as [day]
,datepart(hour, t.sample_time) as [hr]
,datepart(minute, t.sample_time) as [min]  
,convert(varchar(10), t.sample_date, 1) + ' ' + 
  RIGHT('0' + CONVERT([varchar](2), DATEPART(HOUR, t.sample_time)), 2) + ':' +
  RIGHT('0' + CONVERT([varchar](2), DATEPART(MINUTE, t.sample_time)), 2) AS [datetime] 
,t.stationdesc
<cfif isDefined("form.parameter") and ListFindNoCase(form.parameter, "salinity")>,ROUND(t.salinity,1) as salinity</cfif>
<!---plus 6 more parameters--->
FROM (
SELECT    
    [sample_date]
    ,sample_time
    ,stationdesc
    <cfif isDefined("form.parameter") and ListFindNoCase(form.parameter, "salinity") >,salinity</cfif>
    <!---plus 6 more parameters--->
    , row_number() OVER (ORDER BY streamcode) AS rownum
    FROM MyUnionizedTables
    WHERE stationdesc = (<cfqueryparam value="#form.station#" cfsqltype="cf_sql_varchar">)
    AND [sample_date] BETWEEN (<cfqueryparam value='#Form.StartDate#' cfsqltype="cf_sql_date">) 
    AND (<cfqueryparam value='#Form.EndDate#' cfsqltype="cf_sql_date">)
    <cfif isDefined("form.parameter") and ListFindNoCase(form.parameter, "salinity")>and salinity > -25 and salinity <40 and salinity is not NULL  </cfif>
    <!---plus 6 more parameters--->                           
    GROUP BY sample_date, sample_time, stationdesc, streamcode 
    <cfif isDefined("form.parameter") and ListFindNoCase(form.parameter, "salinity")>,salinity</cfif>
    <!---plus 6 more parameters--->
    ) AS t
WHERE    <!---returning Nth row when record sets (count of days between dates selected) are long--->
    <cfif IsDefined("form.station") AND IsDefined("form.parameter") AND #ParamCount# LTE 3 AND form.station eq 'Coastal Bays - Public Landing' and #ctdays# gte 10> t.rownum % 64 = 0 
    <cfelseif IsDefined("form.parameter") AND #ParamCount# LTE 3 AND #ctDays# gte '5840'> t.rownum % 64 = 0 
        <!---plus lots more elseifs--->
    <cfelseif  IsDefined("form.parameter") AND #ParamCount# GTE 7  AND  #ctDays# gte '350'> t.rownum % 8 = 0
    <cfelse>t.rownum % 1 = 0</cfif>
ORDER BY 
     datepart(year, t.sample_date) 
    ,datepart(month, t.sample_date) 
    ,datepart(day, t.sample_date) 
    ,datepart(hour, t.sample_time) 
    ,datepart(minute, t.sample_time) 
此方法用于创建一个以日期/时间为所有15分钟增量的表,从而生成正确绘制的图表(如下所示)。但是,我们不知道如何在不生成多个表的情况下将其扩展到完整的125站完整数据表


在研究了几条建议和大量的研究、尝试和错误之后,我认为我已经解决了我的问题。我需要处理我的额外复杂问题,有时需要减少返回和绘制的数据量,但这部分内容有点超出了我最初问题的范围

我的简短回答是:

  • 创建了MyBigDataTable的表视图,其中包含一个附加列,该列是 名为“TIMEVALUE”的datetime列

  • 制作了一个大的永久性datetime日历表,其中的datetime列名为: “时间价值”

  • 然后,我开发了一组SQL查询

  • (a) 从MyBigDataTable收集数据,并将其放入一个#诱人的

    (b) 还可以从日历表中收集日期时间,并将其放入相同的#表中

    那么, (c) 因为现在有时会有两个日期时间行,一个包含数据,另一个包含数据 对于空值,我运行一个查询,仅在存在数据的情况下才保留包含数据的行 是两行匹配的datetime和station。然后可以将这些数据绘制成图表

  • 这一切现在都动态地写在my.cfm页面、station、date中 范围和参数由用户选择,现在显示图表 已成功绘制日期时间中的正确“间隔”,时间为 缺少数据
  • 以下是SQL(此处仅限于1个参数,但我有8个):


    我需要对它进行全面测试并做一些修改,但我认为这满足了答案的要求,因为到目前为止,它正在做我需要它做的事情。感谢@Leigh和@Dan Bracuk的智慧(和耐心!)

    (编辑)嗯。。。想知道您是否可以每天只生成一个空值,或者是否真的需要为每个缺少的元素生成一个空值。我确信缺失的元素可以在SQL中生成,这只是一个如何和如何高效(即日历表或cte)的问题。是的,字面上的答案是“如果你想打断这行,你需要在其中添加一个null。[1,2,3,null,5,6,7]”。我很震惊没有更好的解决方案。通常我在与另一个表的外部联接中使用这种CTE。所以结果总是包括必要的日期。因此,从概念上讲,结果是这样的
    选择cte.SomeDate,ot.SomeValue从cte LEFT加入other表ot ON ot.SomeDate=cte.SomeDate
    ,即始终填充日期,对于缺少的日期,值最终为
    null
    。(编辑)好的,如果您想尝试“每天单个null”一个有这种类型的工会可能会更好。参见示例。只需将结果与现有日期合并即可。日历表非常有用,但不能完全解决您的问题。您需要在datetime级别绘制值。如果您看到日历表的其他潜在用途(例如会计年度报告),请构建并维护一个日历表。将其与时间问题分开。使用另一个表、表函数或子查询解决该问题。
    --- simulate main table(s)
    --CREATE TABLE MyDataTable ( sample_date datetime, sample_time datetime, stationdesc nvarchar, wtemp float)
    
    --- generate all dates within this range
    DECLARE @startDate datetime
    DECLARE @maxDate datetime
    SET @startDate = '2015-01-01'
    SET @maxDate = '2016-12-31'
    
    --- get MISSING dates
    ;WITH missingDates AS
    (  
        SELECT DATEADD(day,1,@startDate) AS TheDate
        UNION ALL  
        SELECT  DATEADD(day,1, TheDate) 
        FROM    missingDates  
        WHERE   TheDate < @maxDate  
    )
    SELECT *
          --[wtemp]
       --  ,[stationdesc]
       --  ,[TIMEVALUE]
    FROM   missingDates mi LEFT JOIN MyDataTable t ON t.sample_date = mi.TheDate
    WHERE  t.sample_date IS NULL
    --and stationdesc = 'Back River - Lynch Point'
    --ORDER BY timevalue
    OPTION  (MAXRECURSION 0)
    
    --Putting data from only 1 station from our big datatable into the new testtable called '_testdatatable'
    
    SELECT        station, sample_date, sample_time, wtemp, streamcode, stationdesc, TIMEVALUE
    INTO              _testdatatable
    FROM            MyBigDataTable
    WHERE        (stationdesc = 'Back River')
    order by [sample_date],[sample_time]
    
    --Next, make a new table [_testdatatableGap] with all time values in 15min increments from a datetime table we made
    SELECT [wtemp]=null
          ,[streamcode]='ABC1234'
          ,[stationdesc]= 'Back River'
          ,[TIMEVALUE]
          into [tide].[dbo].[_testdatatableGap]
      FROM DateTimeTable
      WHERE  (TIMEVALUE BETWEEN '4/19/2014' AND getdate())
    
    --Then, get the missing dates from the Gap table and put into the testdatatable
    INSERT into [_testdatatable]
          (  [wtemp]
            ,[streamcode]
            ,[stationdesc]
            ,[TIMEVALUE] 
    )
        (SELECT 
           [wtemp]=null -- needs this for except to work
          ,
          [streamcode]
          ,[stationdesc]
          ,
          [TIMEVALUE] 
      FROM [_testdatatableGap]   
    EXCEPT   
    SELECT 
           [wtemp]=null -- needs this for except to work
          ,
        [streamcode]
          ,[stationdesc]
          ,
          [TIMEVALUE] 
      FROM [_testdatatable])
    
    --Step 1. Check if the temptable exists, if it does then delete it
    IF OBJECT_ID('tempdb..#TempTable') IS NOT NULL
    BEGIN
    DROP TABLE #TempTable
    END
    ;
    --Step 2. Create the temptable with data from the parameters, station and dates selected on the .cfm 
    SET NOCOUNT ON
    
    SELECT 
         timevalue
        ,stationdesc
        ,wtemp
    INTO #TempTable
    
    FROM MyBigDataTable
    WHERE 
        stationdesc = 'Station01'
        and [timevalue] BETWEEN '5/29/2014' AND '10/01/2016'
    GROUP BY 
        TIMEVALUE
        ,stationdesc
        ,wtemp
    ;
    --Step 3. Now select datetimes from a big calendar table, and set stationdesc to the selected station, 
    --and rest of parameters to null. And do this for the same selected date range
    INSERT INTO #TempTable
    SELECT 
    [TIMEVALUE] 
    ,[stationdesc]= 'Station01' 
    ,wtemp=null
    FROM MyDatetimeCalendarTable
    WHERE  [timevalue] BETWEEN '5/29/2014' AND '10/01/2016'
    ;
    --Step 4. Run query on the temptable to gather data for chart, but b/c sometimes there will be 2 rows with the same datetime and station but one with data and one with nulls, this query only gathers the row with data if there are 2 rows with matching datetime and station
    SELECT distinct *
    FROM #TempTable a
    WHERE 
    wtemp is not null or
        wtemp is null and 
        not exists(
            SELECT * FROM #TempTable b
            WHERE a.timevalue=b.timevalue 
    and a.stationdesc=b.stationdesc and b.wtemp is not null)
    ORDER BY timevalue
    ;