Graphics

 View Only
  • 1.  Sort data?

    Posted 11-22-2022 03:54
    Hello.

    Right now i'm using this script:
    ' Load the JSON data from hidden texts to array
    ' The hidden texts have the DataLinq that ties each one to one entry in the JSON array
    Dim xdata(15) As String
    Dim ydata(15) As Double
    Dim zdata(15) As Double
    For i As Integer = 1 to 16
        Dim letter, percent, percentch As xpTextObject
    		Self.GetObjectByName("hiddenLetter" & i, letter)
        Self.GetObjectByName("hiddenPercent" & i, percent)
    		Self.GetObjectByName("hiddenPercentCh" & i, percentch)
    		xdata(i - 1) = letter.Text
    		ydata(i - 1) = CDbl(percent.Text.Replace(".", ","))
    		zdata(i - 1) = CDbl(percentch.Text.Replace(".", ","))
    Next
    
    ' Now we have the data as numbers we can sort
    Array.Sort(ydata)
    Array.Reverse(ydata)
    
    ' Last step, put the sorted data into the visible text objects
    For i As Integer = 1 to 16
        Dim percent As xpTextObject
        Self.GetObjectByName("Procent " & i, percent)
        percent.Text = ydata(i - 1).ToString("N1") + "%"
    Next​

    It's only sorting ydata and putting ydata in a textobject.

    I have startet to read out data that I have to show together with the actual ydata.
    How can I make sure that it is the right party letter and +/- percent that I show?

    Best regards Tue.

    ------------------------------
    Tue Sandbæk
    Director / TV-Technician
    TV SYD
    ------------------------------


  • 2.  RE: Sort data?

    Posted 11-30-2022 08:31
    Any one?

    ------------------------------
    Tue Sandbæk
    Director / TV-Technician
    TV SYD
    ------------------------------



  • 3.  RE: Sort data?

    Posted 12-06-2022 13:22
    Things get trickier when sorting data with multiple fields. I would put the data in an array of 3 items. Then put those arrays into a List. You will need to create a custom sorter function. Since Xpression doesn't seem to support Linq or lambda expressions, put this in your global script:
    Function DoSort(ByVal a As Object(), ByVal b As Object()) As Integer
      DoSort = b(1).CompareTo(a(1))
    End Function​
    This creates a function that sorts on the 2nd item of an array.
    Then change the script to something like this:
    ' Create a list of arrays
    Dim data As New System.Collections.Generic.List(Of Object())
    
    ' Put the data from the hidden text objects in the list 
    For i As Integer = 1 to 16
      Dim letter, percent, percentch As xpTextObject
      Self.GetObjectByName("hiddenLetter" & i, letter)
      Self.GetObjectByName("hiddenPercent" & i, percent)
      Self.GetObjectByName("hiddenPercentCh" & i, percentch)
      ' Put the data in an array
      Dim ar As Object() = {letter.Text, CDbl(percent.Text.Replace(".", ",")), CDbl(percentch.Text.Replace(".", ","))}
      ' Add the array to the list
      data.Add(ar)
    Next
    
    ' Sort the list using the custom function
    data.Sort(AddressOf DoSort)
    
    ' Put the sorted data into the graphics
    For i As Integer = 1 to 16
      Dim letter, percent, percentch As xpTextObject
      Self.GetObjectByName("Letter" & i, letter)
      Self.GetObjectByName("Percent" & i, percent)
      Self.GetObjectByName("PercentCh" & i, percentch)
      letter.Text = data(i - 1)(0)
      percent.Text = data(i - 1)(1).ToString("N1") + "%"
      percentch.Text = data(i - 1)(2).ToString("N1") + "%"
    Next


  • 4.  RE: Sort data?

    Posted 12-12-2022 06:46
    I changed now the script, without a sort function.
    Right now just try to save the data in array and get back.

    Dim data As New System.Collections.Generic.List(Of Object())
    
    For i As Integer = 1 to 16
    	Dim letter, percent, percentch As xpTextObject
    	Self.GetObjectByName("hiddenLetter" & i, letter)
    	Self.GetObjectByName("hiddenPercent" & i, percent)
    	Self.GetObjectByName("hiddenPercentCh" & i, percentch)
    
    	Dim ar As Object() = {letter.Text, CDbl(percent.Text.Replace(".", ",")), CDbl(percentch.Text.Replace(".", ","))}
    
    	data.Add(ar)
    Next
    
    For i As Integer = 1 to 16
    	Dim letter, percent, percentch As xpTextObject
    	Self.GetObjectByName("Bogstav " & i, letter)
    	Self.GetObjectByName("Procent " & i, percent)
    	Self.GetObjectByName("ProcentCh " & i, percentch)
    	letter.Text = data(i - 1)(0)
    	percent.Text = data(i - 1)(1).ToString("N1") + "%"
    	percentch.Text = data(i - 1)(1).ToString("N1") + "%"
    Next​

    But nothing happens, am I doing anything wrong here?



    ------------------------------
    Tue Sandbæk
    Director / TV-Technician
    TV SYD
    ------------------------------



  • 5.  RE: Sort data?

    Posted 12-12-2022 10:45
    Since the type of the array is Object, you need to cast to double before calling ToString. Change those 2 lines to:

    percent.Text = CDbl(data(i - 1)(1)).ToString("N1") & "%"
    percentch.Text = CDbl(data(i - 1)(2)).ToString("N1") & "%"​



    ------------------------------
    JohnCorigliano
    Senior Software Engineer
    ISC
    ------------------------------