DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding horizontal line to programmatically created graph

As part of a larger "application", we have a script which produces magnitude-vs-time graphs for all channels collected in a data set.  These graphs are produced entirely by the scripts - no report layouts are used.  We want to add a second "curve" to the existing curve for selected channels to add a "limit" line representing the maximum value of the signal (but not contained in a separate channel).  See attached for an illustration of what is desired.

 

It seems like this should be a relatively easy task, but I have not yet been able to construct workable code to accomplish this task.  Any suggestions or assistance would be greatly appreciated.   

 

Regards,

Bill Evans

0 Kudos
Message 1 of 9
(5,717 Views)

Hi WFEvans,

 

For the new REPORT syntax it looks like this:

 

dim oConst, oConstShape
Set oConst = Report.ActiveSheet.Objects.Item("2D-Axis1").Curves2D.Add(e2DShapeConstant, "new_constant")
set oConstShape = oConst.Shape
oConstShape.XConstant.Reference = "NOVALUE"
oConstShape.YConstant.Reference = myValue
oConstShape.Settings.Line.Color.ColorIndex = eColorIndexBlack 

 

For the old syntax it is:

call GraphObjOpen("2DAxis1")
  Call GraphObjNew("2D-curve", "new_constant")
  Call GraphObjOpen("new_constant")
    D2CCurveType     = "Constant"
    D2CConstXName    = "NOVALUE"
    D2CConstYName    = "32"
    D2CurveColor     = "green"
  Call GraphObjClose("new_constant")
Call GraphObjClose("2DAxis1")

 We implemented the new syntax in DIAdem 2012 (but the old one is of course still working)

 

Greetings

Walter

0 Kudos
Message 2 of 9
(5,703 Views)

Walter,

 

Thanks for the quick reply.  I have tried to integrate the "old version" syntax you provided into my existing script, but I still do not have a visible horizontal line on the selected graphs.  Just to make sure I understand the syntax, the line D2CConstYName  = "32" determines the y-axis value for the horizontal line, right?  Also, I assume this value can be a real (non-integer) number (provided it is within the maximum range of the y-axis.

 

My modifications to the code for integration with my script are as follows:

  Call GraphObjOpen("2DAxis1")
  Call GraphObjNew("2D-curve", "2DObj1_Curve2")
  Call GraphObjOpen("2DObj1_Curve2")
    D2CCurveType     = "Constant"
    D2CConstXName    = "NOVALUE"
    D2CConstYName    = "12.78"
    D2CurveColor     = "black"
  Call GraphObjClose("2DObj1_Curve2")
  Call GraphObjClose("2DAxis1")

 

I am using "2DObj1_Curve2" as the object name (since I have already created a "2DObj1_Curve1") instead of the "new_constant" name in your example.  Also, I am using the old syntax since I am currently working with DIAdem 2011 (11.3.1f4723 TDM Service Pack 1).  Do you see anything wrong with this?

 

Thanks again,

 

Bill Evans

720-988-3436

 

 

0 Kudos
Message 3 of 9
(5,696 Views)

Bill,

 

did you refresh the REPORT after setting the constant?

 

Greetings

Walter

0 Kudos
Message 4 of 9
(5,694 Views)

Walter,

 

I do have a refresh (Call PicUpdate) at the end of the code that creates all the graphs.  For testing purposes, I have added a refresh immediately following the code that should draw the horizontal line but this seems to have no effect. 

 

Bill Evans

720-988-3436

0 Kudos
Message 5 of 9
(5,691 Views)

Hi Bill,

 

Your code makes a horizontal line on a graph in my DIAdem REPORT in both DIAdem 2011 and DIAdem 2012.  All I had to add was the PicUpdate command to force the refresh afterwards.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 6 of 9
(5,677 Views)

Brad,

 

Thanks for the confirmation that the code works on your system.  I can produce a 2D graph with the specified horizontal line if I use just that code snippet and no other curve objects on the graph.  However, as soon as I add the code snippet for the horizontal line to the other code in my script (to produce a signal curve from a channel plus the horizontal line), I fail to get the line on the resultant graph.  It looks like the other code I use to create either the channel signal curve and/or the other graph components (axes, axes titles, etc.) may be "interfering" with (or perhaps overwriting) the horizontal line.

 

In order to simplify things for troubleshooting purposes, I have abstracted only the script code required to produce a single channel, and have added the code snippet to produce the horizontal line.  In testing, this produces the channel signal code but again does not produce the desired horizontal line.  Attached is a document showing the results of this test script, and a copy of the script code.  From the overall behavior or structure of the code, can you suggest a possible area in the code for me to explore further?

 

By the way, I do have a work-around, but it is not necessarily the way I'd like to proceed.  If I create a new channel with all values set at the 12.84 value for the horizontal line, I can plot both channels on the same graph by plotting both as curves.  This requires the production of additional channels which I would prefer to avoid if at all possible.

 

Thanks for any help you can provide.

 

Regards,

 

Bill Evans

720-988-3436

0 Kudos
Message 7 of 9
(5,671 Views)

Hi Bill,

 

I got the code you submitted to work by specifying (PicDefIdent=1) that all programmatic calls should be channel-name-based, not channel-number-based, then using the channel-name-based variables (D2CChnXName, D2CChnXName) instead of the channel-number-based variables you were using.

 

I think that was all that was required,

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 8 of 9
(5,659 Views)

Brad,

 

Thanks for the information and the revised code.  I have completed integrating it into my full script and it works exactly as desired.  I appreciate your help.

 

Bill Evans

720-988-3436

0 Kudos
Message 9 of 9
(5,642 Views)