Showing results for 
Search instead for 
Did you mean: 

custom text in curve legend using script

Go to solution



is there a way to have a custom text in curve legend using script?


Legend: channel name & "user text"

user text is a variable.



is there a way to set expression in curve legend using script?

 Expression: @@.....@@


Everything I would like to do using script alone.




0 Kudos
Message 1 of 3
Accepted by Durai26

Hello Durai,


are you using a 2D axis system in REPORT or in VIEW? I assume you mean REPORT. 😊


In REPORT, a curve-related text can be displayed in the legend in an axis system. For this purpose, an individual text is set for each curve, which can be composed of any variables. However, an expression can also be used as free text for all curves. In this way, for example, the maximum of each curve can be displayed in a column of the legend. It will look like this.


Dim oMy2DAxisSystem, oMyPos, oMy2DCurve1, oMy2DCurve2
Dim oLegendPosition, oLegendColRelatedText, oLegendColExpression

Call Data.Root.Clear()
Call DataFileLoad(DataReadPath & "Example.tdm", "TDM", "Load|ChnXYRelation")

Call Report.NewLayout()

Set oMy2DAxisSystem = Report.ActiveSheet.Objects.Add(eReportObject2DAxisSystem, "My2DAxisSystem")
Set oMyPos = oMy2DAxisSystem.Position.ByCoordinate
oMyPos.X1 = 20
oMyPos.X2 = 80
oMyPos.Y1 = 10
oMyPos.Y2 = 60

Set oMy2DCurve1 = oMy2DAxisSystem.Curves2D.Add(e2DShapeLine, "My2DCurve1")
oMy2DCurve1.Shape.XChannel.Reference = ""
oMy2DCurve1.Shape.YChannel.Reference = "[4]/[1]" 
Set oMy2DCurve2 = oMy2DAxisSystem.Curves2D.Add(e2DShapeLine, "My2DCurve2")
oMy2DCurve2.Shape.XChannel.Reference = ""
oMy2DCurve2.Shape.YChannel.Reference = "[4]/[2]" 

' Legend 
dim CurveYChn : set CurveYChn = Data.GetChannel(oMy2DCurve1.Shape.YChannel.Reference)
dim FirstChnValue : FirstChnValue = CurveYChn.Values(1)

oMy2DAxisSystem.CurveLegend.Visible = True

' Add column with curve related text
Set oLegendColRelatedText = oMy2DAxisSystem.CurveLegend.Columns.Add()
oLegendColRelatedText.Title = "Curve related text"
oLegendColRelatedText.Type = eLegendTextCurveRelatedText
oMy2DCurve1.RelatedLegendText(2) = FirstChnValue
oMy2DCurve2.RelatedLegendText(2) = CurveYChn.GetReference(eReferenceIndexName)

' Add column with one expression for all curves
Set oLegendColExpression = oMy2DAxisSystem.CurveLegend.Columns.Add()
oLegendColExpression.Title = "Expression"
oLegendColExpression.Type = eLegendTextCustomText
oLegendColExpression.Text = "@@Data.GetChannel(CurrChnNo).Maximum@@"

Set oLegendPosition = oMy2DAxisSystem.CurveLegend.Position
oLegendPosition.Anchor.Type = eLegendAnchorTypeSystemRelated
oLegendPosition.Anchor.SystemRelatedX = 0
oLegendPosition.Anchor.SystemRelatedY = 110
oLegendPosition.RelativePosition = eLegendRelativePositionBottomLeft
oLegendPosition.ElementHeight = 10
oLegendPosition.ElementWidth = 40

Call Report.Refresh()




Message 2 of 3

It works great.


@AnJalpaka Thanks a lot.

0 Kudos
Message 3 of 3