从Excel绘制TimeStamp数据

时间:2013-08-19 23:30:27

标签: excel

我的excel表上记录了数据。这个数据实际上是时间戳。

我想绘制我记录的时间戳第一个图像值,类似于下面的第二个图。

recorded time stamps

Want to have this format



1 个答案:

答案 0 :(得分:2)

回答你的问题和你的评论,你想要及时建立事件的直方图。

您需要定义所需的bin大小。假设您的垃圾箱大小为5分钟,并且您希望将直方图绘制24小时。

手动执行

按如下方式创建一个小表:

         A      |  B                |  C
  -----------------------------------------------------
1 |    start    | end               | event_count
2 |    00:00:00 | =A2 + time(0,5,0) | =countIfS(dataSheet!G:G,">=" & A2,dataSheet!G:G,"<" & B2)
3 |    =B2      | =A3 + time(0,5,0) | =countIfS(dataSheet!G:G,">=" & A3,dataSheet!G:G,"<" & B3)

根据需要复制第3行中的公式。然后创建一个条形图。

请注意,在单元格B2B3,......中写入的公式中的值是您指定的bin的大小。

使用代码

由于这是一个编程Q&amp; A网站,因此需要编程解决方案:

public sub createMyTimeHistogram(inputRange as Range, binSize as integer)
' Parameters:
'    inputRange: The range that stores the data
'    binSize: The size of the bin (in minutes)

    Dim t as Date
    Dim n as Integer
    Dim outputSheet as String, outputRow as long


    t = timeserial(0,0,0)
    outputSheet = "MyOutputSheet" ' I'll assume this worksheet exists in the current workbook,
                                  ' and it is empty
    With thisWorkbook.Sheets(outputSheet)
        .cells(1,1).value = "Bin"
        .cells(1,2).value = "Count"
    End With
    outputRow = 2
    while t < 1
        n = Excel.WorksheetFunction.CountIfS(inputRange, ">=" & CDbl(t), inputRange, "<" & CDbl(t + timeserial(0,binSize,0)))
        With thisWorkbook.Sheets(outputSheet)
            .cells(outputRow, 1).Value = t
            .cells(outputRow, 2).Value = n
        End With
        t + timeserial(0,binSize,0)
        outputRow = outputRow + 1
    wend
end sub