DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

DateTime scaling in script doesn't seem to work

I'm trying this code to alter my axis' scaling based on a previous event search. I'm getting an error when I try "oMy2DAxisSystem.XAxis.Scaling.Begin" = <Date> saying "Numeric value necessary". So it seems that I'm not actually able to change the property "oMy2DAxisSystem.XAxis.Scaling.Type"

 

Set o2DAxisXScaling = oMy2DAxisSystem.XAxis.Scaling
oMy2DAxisSystem.XAxis.Scaling.AutoScalingType = eAxisAutoScalingBeginEndManual
o2DAxisXScaling.Type = e2DxScalingDateTime
oMy2DAxisSystem.XAxis.Scaling.Begin = CDate(Data.Root.ChannelGroups(1).Channels("DateTime").Values(indexbeginning))
oMy2DAxisSystem.XAxis.Scaling.End = CDate(Data.Root.ChannelGroups(1).Channels("DateTime").Values(indexend))

0 Kudos
Message 1 of 2
(2,230 Views)

You didn't specify if this is a 2D curve in the View or Report panel. Looks to me like Report objects. What concerns/confuses me is you reference a "DateTime" channel as Data.Root.ChannelGroups(1).Channels("DateTime").Values() ... but you attempt to convert a specific value to a date usin cDate(). If "DateTime" is not a channel of type time (holds date/time values), then the cDate conversion may be valid depending on the .Values() in the channel. 

 

Below is a solution to plotting a DateTime channel on the X-Axis of a Report 2D curve  (also available at: http://localhost/bws/savvydiademsolutions/report.php?topic=report-2d-chart-datetime-xaxis).  

 

'-------------------------------------------------------------------------------
'-- VBS script file
'-- Author: Mechatronic Solutions LLC
' Mark W Kiehl
' www.SavvyDiademSolutions.com
' www.MechatronicSolutionsLLC.com
'-- Comment:
'-------------------------------------------------------------------------------
Option Explicit

Call bCreateRpt2DchtDateTimeXaxis()

Function bCreateRpt2DchtDateTimeXaxis()

'-------------------------------------------------------------------------------
' Create a Report sheet 2D chart with DateTime X-Axis

'Load a single numeric time channel + three numeric data channels "Speed","RPM","Torque"
Call Data.Root.Clear(): Portal.NoOfGroupsToExpand = 1
If FileExist(sFilePathDIAdemExample("Example.tdm")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example.tdm"),"TDM","[1]/*")
ElseIf FileExist(sFilePathDIAdemExample("Example.tdms")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example.tdms"),"TDMS","[1]/*")
ElseIf FileExist(sFilePathDIAdemExample("Example_data.tdm")) Then
Call DataFileLoadSel(sFilePathDIAdemExample("Example_data.tdm"),"TDM","[1]/*")
Else
Call LogFileWrite("DIAdem example files cannot be found")
End If
Dim oGrp, oChnTime, oChnDateTime, oChnX, oChnY
Dim oRptSht, oRptObj, oCurve2D, iCurve, oElement, eNSystemsMode
Set oGrp = Data.Root.ChannelGroups("Example")
Set oChnTime = oGrp.Channels("Time")

'Create a DateTime channel of type time
Set oChnDateTime = oGrp.Channels.AddChannel(oChnTime, 2)
oChnDateTime.Name = "DateTime"
'NOTE: This data doesn't have any absolute date/time reference, including time zone.
' If you have an absolute reference, it should be included with your data.
' The absolute reference of the storage date/time will be used for this example.
Call ChnNumericToTime(oChnDateTime, Data.Root.Properties("datetime").Value, False)
Call ChnCharacterAll()
Call LogFileWrite("oChnDateTime.Minimum = " & Str(oChnDateTime.Minimum,"#dd-ttt-yyyy hh:nn:ss,ffff AMPM") & " = " & oChnDateTime.Minimum & " sec since 1 Jan 0000" )

'I like to generalize the Report 2D chart channel references to oChnX and oChnY
Set oChnX = oChnDateTime: Set oChnY = oGrp.Channels("Speed")
Call Report.NewLayout()

'Add a new Report sheet
Set oRptSht = Report.Sheets.Add(sGetUniqueReportSheetName("2dChtDateTimeXaxis","")): Call Report.Refresh()
'Create the 2D chart
Set oRptObj = oRptSht.Objects.Add(eReportObject2DAxisSystem, "2DAxisNSystems")
oRptObj.Position.ByCoordinate.X1 = 12
oRptObj.Position.ByCoordinate.X2 = 95
oRptObj.Position.ByCoordinate.Y1 = 22
oRptObj.Position.ByCoordinate.Y2 = 84
'Frame the grid
oRptObj.Settings.Grid.DisplayMode=e2DAxisGridModeFrame

iCurve = 0
iCurve = iCurve + 1
Set oCurve2D = oRptObj.Curves2D.Add(e2DShapeLine, "2DCurve" & str(iCurve))
oCurve2D.Shape.XChannel.Reference = oChnX.GetReference(eRefTypeIndexIndex)
oCurve2D.Shape.YChannel.Reference = oChnY.GetReference(eRefTypeIndexIndex)

'X-Axis label
oRptObj.XAxis.Label.Text = "@@ChnName(CurrChnNo)@@ [@@ChnDim(CurrChnNo)@@]"
oRptObj.XAxis.Label.Text = oChnX.Name & " [" & oChnX.UnitSymbol & "]"
oRptObj.XAxis.Label.UseCurveColor = False
oRptObj.XAxis.Label.Font.Color.ColorIndex = eColorIndexBlack
oRptObj.XAxis.Numbers.Font.Color.ColorIndex = eColorIndexBlack
oRptObj.XAxis.Numbers.Format = "#dd-ttt-yyyy hh:nn:ss.ffff"
oRptObj.XAxis.Numbers.Font.Size = 2.2
oRptObj.XAxis.Numbers.Angle = 45
oRptObj.XAxis.Numbers.RelativePosition=eRelativePositionLeftBottom
oRptObj.XAxis.Scaling.AutoScalingType = eAxisAutoScalingCompleteAutomatic
oRptObj.XAxis.Scaling.Begin = oChnX.Minimum
oRptObj.XAxis.Scaling.End = oChnX.Maximum
oRptObj.XAxis.Scaling.MiniTickCount = 1
oRptObj.XAxis.Scaling.Type = e2DXScalingLinear

'Show the Y-Axis labels if eNSystemsMode = e2DAxisNSystems
eNSystemsMode = e2DAxisNSystems
If eNSystemsMode = e2DAxisNSystems Then
oRptObj.YAxis.Label.Text = "@@ChnName(CurrChnNo)@@ [@@ChnDim(CurrChnNo)@@]"
Else
oRptObj.CurveLegend.Visible = True
oRptObj.CurveLegend.Frame.Visible = False
oRptObj.CurveLegend.Position.InteractiveMoveMode=eLegendMoveAutomatic
oRptObj.CurveLegend.Position.RelativePosition = eLegendRelativePositionTopLeft
oRptObj.CurveLegend.Position.SizeMode =eLegendSizeElementwise
oRptObj.CurveLegend.Position.Anchor.Type=eLegendAnchorTypePageRelated
oRptObj.CurveLegend.Position.Anchor.PageRelatedX = 75
oRptObj.CurveLegend.Position.Anchor.PageRelatedY = 90
oRptObj.CurveLegend.Settings.UseAutoFontSize = False
oRptObj.CurveLegend.Settings.Font.Size = 3.0
End If
oRptObj.Settings.NSystemsMode = eNSystemsMode
oRptObj.YAxis.Label.UseCurveColor = False
oRptObj.YAxis.Label.Font.Color.ColorIndex = eColorIndexBlack
oRptObj.YAxis.Numbers.Font.Color.ColorIndex = eColorIndexBlack
oRptObj.YAxis.Scaling.AutoScalingType=eAxisAutoScalingCompleteAutomatic

'Title
Set oRptObj = oRptSht.Objects.Add(eReportObjectText, "RptTitle")
oRptObj.Font.Size = 6
oRptObj.Font.Bold = True
oRptObj.PositionXY.X = 52.132
oRptObj.PositionXY.Y = 95.648
oRptObj.PositionXY.RelativePosition = eRelativePositionCenter
oRptObj.Text = "2D Chart With DateTime X-Axis"
Set oRptObj = Nothing

'Sub Title
Set oRptObj = oRptSht.Objects.Add(eReportObjectText, "RptSubTitle")
oRptObj.Font.Size = 5
oRptObj.PositionXY.X = 52.132
oRptObj.PositionXY.Y = 89.824
oRptObj.PositionXY.RelativePosition = eRelativePositionCenter
oRptObj.Text = "www.SavvyDIAdemSolutions.com"
Set oRptObj = Nothing

'Metadata at upper right
Set oRptObj = oRptSht.Objects.Add(eReportObjectText, "RptMetadata")
oRptObj.Font.Size = 2
oRptObj.PositionXY.X = 97
oRptObj.PositionXY.Y = 97
oRptObj.PositionXY.RelativePosition =eRelativePositionLeftBottom
oRptObj.Text = Str(Now(),"#dd-ttt-yyyy") & vbCrLf & Data.Root.Name
Set oRptObj = Nothing

Call Report.Refresh()

End Function 'bCreateRpt2DchtDateTimeXaxis()

'===============================================================================
' Helper functions


Function sGetUniqueReportSheetName(ByVal sPrefix, ByVal sSuffix)
'Returns a unique View sheet name with
'optional parameters sPrefix and sSuffix included in the
'new sheet name.
sGetUniqueReportSheetName = ""
Dim sSheet, i
i = 0
Do
If i = 0 Then
sSheet = Trim(sPrefix) & Trim(sSuffix)
Else
sSheet = Trim(sPrefix) & Trim(sSuffix) & Str(i)
End If
i = i + 1
Loop Until Not Report.Sheets.Exists(sSheet)
sGetUniqueReportSheetName = sSheet
End Function 'sGetUniqueReportSheetName()

 

Function sFilePathDIAdemExample(ByVal sFilename)
'Returns the full absolute file/path for the location of the DIAdem
'example (TDM/TDMS) file sFilename. Looks in the usual places.
'Returns "" if the file cannot be found.
sFilePathDIAdemExample = ""
Dim arrFilePaths, sFilePath, sFolder
ReDim arrFolders(1)
arrFolders(0) = ProgramDrv
arrFolders(1) = CommonDocumentsPath
Call MsgLineDisp("Searching DIAdem examples for file '" & sFilename & "'..")
For Each sFolder In arrFolders
arrFilePaths = DirListGet(sFolder,sFilename,"Date/Time","FullFilenamesRecursive")
If IsArray(arrFilePaths) Then
For Each sFilePath In arrFilePaths
If InStr(1,sFilePath,"Libr",vbTextCompare) = 0 Then
sFilePathDIAdemExample = sFilePath
Exit For
End If
Next
End If
If Len(sFilePathDIAdemExample) > 0 Then Exit For
Next
If IsArray(arrFilePaths) Then Call Erase(arrFilePaths)
If IsArray(arrFolders) Then Call Erase(arrFolders)
Call MsgLineDisp(vbTab)
End Function 'sFilePathDIAdemExample()

 

0 Kudos
Message 2 of 2
(1,709 Views)