Graphics

 View Only
  • 1.  Sort data?

    Posted 15 days ago
    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 7 days ago
    Any one?

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



  • 3.  RE: Sort data?

    Posted yesterday
    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