DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Find maximum Y value of all curves in a 2DAxis chart

Solved!
Go to solution

Hi,

 

Is there a way to get maximum Y value of all the Y values in a chart?

 

The number of curves, Y channel and Y channel expression will be changing with respect to report template used. Need to refer the channels and expression used in report template to find maximum Y value among all the curves in the chart.

 

Is there any DIAdem script command to do it in a better way?

 

Example:

In this template, 5 curves with 3-Y channels and 2 -Y expression channels. How to find the maximum value of Y among these 5 curves using DIAdem scripts? 

 

Durai26_0-1689015038717.png

 

Regards,

Durai

 

0 Kudos
Message 1 of 7
(3,221 Views)
Call LogFileDel
Call GetMaxOfAllViewSheetCurves()

Function GetMaxOfAllViewSheetCurves()

  Dim oSheet, oArea, oCurve, oChnX, oChnY
  
  Set oSheet = View.ActiveSheet
  Set oArea = oSheet.ActiveArea

  For Each oArea In oSheet.Areas
    If oArea.DisplayObjType = "CurveChart2D"Then
      For Each oCurve In oArea.DisplayObj.Curves2D
        Set oChnY = Data.GetChannel(oCurve.YChannelName)
        Call ChnCharacter(oChnY)
        Call LogFileWrite("Curve # " & oCurve.Index & vbTab & oChnY.GetReference(eReferenceIndexName) & vbTab & " max: "  & Str(oChnY.Maximum,"AutoAdj") & " " & oChnY.UnitSymbol)        
      Next
    End If
  Next

End Function  'GetMaxOfAllViewSheetCurvesIO
0 Kudos
Message 2 of 7
(3,190 Views)

Hi Mark,

 

will the code work with report sheet?

 

I am trying to do it in report template. Some curves are having expression in Y channel.

 

Durai26_0-1689072218622.png

 

 

regards,

Durai

0 Kudos
Message 3 of 7
(3,182 Views)

Hello Durai26,

 

in REPORT you can get the maximum y value from all visible curves with this VBS function. It also considers constants that contain an expression.

function GetMaxYValueFromCurves(Curves)
  dim Curve, MaxValue, CurveValue
  
  for each Curve in Curves
    ' Only visible curves
    if Curve.Enable then
      if Curve.ShapeType = e2DShapeLineAndPoints or Curve.ShapeType = e2DShapeLine then
        CurveValue = Data.GetChannel(Curve.Shape.YChannel.Reference).Maximum
      elseif Curve.ShapeType = e2DShapeConstant then
        if instr(Curve.Shape.YConstant.Reference, "@@") > 0 then
          CurveValue = eval(replace(Curve.Shape.YConstant.Reference, "@", ""))
        else
          CurveValue = val(Curve.Shape.YConstant.Reference, Novalue)
        end if
      end if
      if IsEmpty(MaxValue) or CurveValue > MaxValue then
        MaxValue = CurveValue
      end if
    end if
  next
  GetMaxYValueFromCurves = MaxValue
end function

print(GetMaxYValueFromCurves(Report.ActiveSheet.Objects("2DAxis1").Curves2D))
0 Kudos
Message 4 of 7
(3,158 Views)

Hi AnJalpaka,

 

Thanks a lot for your suggestion, it was great to have some scripts like this.

 

It works fine for one of my template but unfortunately it throws error in my another template.

 

My report template refers to a particular channel and some situation there is no such channel exist in data portal. Since no channel exist, I am getting error in the below line,

 

CurveValue = Data.GetChannel(Curve.Shape.YChannel.Reference).Maximum

 

is there a option to check for channel existing before fetching the value? How to skip these lines if there is no channel present in data portal?

 

Also, sometimes channel exists but it has NOVALUE in maximum and minimum properties. Even in these scenario, it throws error.

Durai26_0-1689273297425.png

Durai26_2-1689273402448.png

 

 

 

 

regards,

Durai

 

0 Kudos
Message 5 of 7
(3,130 Views)
Solution
Accepted by topic author Durai26

Hello Durai26,

 

The script can of course safeguard other circumstances, such as Novalues or non-existent channels. If the maximum of a channel is not known, it can be determined by the ChnCharacter command. If you don't want this, then take out the section with the call of ChnCharacter.

 

function GetMaxYValueFromCurves(Curves)
  dim Curve, MaxValue, CurveValue, Channels, Chn
  
  for each Curve in Curves
    ' Only visible curves
    if Curve.Enable then
      if Curve.ShapeType = e2DShapeLineAndPoints or Curve.ShapeType = e2DShapeLine then
        set Channels = Data.GetChannels(Curve.Shape.YChannel.Reference)
        if Channels.Count = 1 then
          set Chn = Channels(1)
          if IsNull(Chn.Maximum) then
            ' Calculate maximum value
            call ChnCharacter(Chn)
          end if
          CurveValue = Chn.Maximum
        end if
      elseif Curve.ShapeType = e2DShapeConstant then
        if instr(Curve.Shape.YConstant.Reference, "@@") > 0 then
          CurveValue = eval(replace(Curve.Shape.YConstant.Reference, "@", ""))
        else
          CurveValue = val(Curve.Shape.YConstant.Reference, Novalue)
        end if
      end if
      if not IsNull(CurveValue) then
        if IsEmpty(MaxValue) or CurveValue > MaxValue then
          MaxValue = CurveValue
        end if
      end if
    end if
  next
  GetMaxYValueFromCurves = MaxValue
end function
Message 6 of 7
(3,107 Views)
0 Kudos
Message 7 of 7
(3,068 Views)