B4J Library [B4X] [XUI] xChart Class and b4xlib

klaus

Expert
Licensed User
Longtime User
What exactly do you want to display for Private on this Tag 2022-07-01 with two values ?
Maybe the method name AddLineMultiplePoints might be confusing.
AddLineMultiplePoints means a chart with more than 1 line.
And the AddLineMultiplePoints method adds an Array of Y values for the given Tag, one point for each line.
AddLinePointData adds a single point to a single line chart.
So, again, what do you expect on the chart with your data.
Do you have an example chart.
 

Tecuma

Member
Licensed User
@klaus
My post should be in the xChartLite thread. I guess the behaviour is the same for both libraries.

I saw your comment

B4X:
' In the case of 2 lines or more we are adding an array of values.
' One for each line.
' Make sure to create an array for each point.
' You cannot reuse a single array for all points.

I tested LineCharts with AddLineMultiplePoints.

E.g. working
B4X:
    LineChart.AddLineMultiplePoints(1, Array As Double (1, 2, 3, 6), True)
    LineChart.AddLineMultiplePoints(2, Array As Double (1, 3, 5, 8), True)

E.g. not working
B4X:
    LineChart.AddLineMultiplePoints(1, Array As Double (1, 2, 3, 6), True)
    LineChart.AddLineMultiplePoints(2, Array As Double (1, 3, 5, 8), True)
    LineChart.AddLineMultiplePoints(3, Array As Double (1, 9, 11), True)

From my understanding I need all the time the same amount of values for all lines.
I will change my graph(s) for this requirement so I am fine.
 

klaus

Expert
Licensed User
Longtime User
From my understanding I need all the time the same amount of values for all lines.
Yes.

In the xChart.b4xlib, the full version, you have an option for missing values.
If you set any value in your array to the MissingDataValue which is by default : 1000000000, this value will not be displayed.
 

JdV

Active Member
Licensed User
Longtime User
Hi

Is there a way to remove all interactivity from a chart?

I have set both DisplayCursor and DisplayValues to False but it still allows me to click on the chart.

Regards

Joe
 

klaus

Expert
Licensed User
Longtime User
... but it still allows me to click on the chart.
I suppose that you mean that the cursor is displayed when you click on a chart.

Can you please try the attached version 9.1 ?

EDIT: The xChart.b4xlib has been removed.
 
Last edited:

JdV

Active Member
Licensed User
Longtime User
I suppose that you mean that the cursor is displayed when you click on a chart.

Can you please try the attached version 9.1 ?
That has worked perfectly!

Thanks for the quick response.
 

bdunkleysmith

Active Member
Licensed User
Longtime User
From a table containing the lead of a sporting game Vs game time I use the xChart library with this code:
B4X:
XYChart1.AddYXLine("Lead", xui.Color_Red, 1)
Dim tmp As String
For r = 0 To tv1.Items.Size - 1
    tv1.SelectedRow = r
    Dim ap1 As AnchorPane = tv1.SelectedRowValues(0)
    Dim lbl1 As Label = ap1.GetNode(0)
    Dim ap2 As AnchorPane = tv1.SelectedRowValues(4)
    Dim lbl2 As Label = ap2.GetNode(0)
    If r > 0 Then XYChart1.AddYXPoint(0, MinSecToDecMins(lbl1.Text), tmp)
    If r = 0 Then XYChart1.AddYXPoint(0, MinSecToDecMins(lbl1.Text), 0)
    XYChart1.AddYXPoint(0, MinSecToDecMins(lbl1.Text), lbl2.text)
    tmp = lbl2.text
Next
to produce this XY chart:



I would like the chart line to be red if the lead is negative and blue if it is positive, but can accept the zero crossing vertical line to be either color.

It seems I cannot just change the line color depending on whether the lead is positive or negative, but must create a new line in the appropriate color when it crosses the horizontal axis. Or am I overlooking a simple way to change the line color as it crosses the X axis?
 

bdunkleysmith

Active Member
Licensed User
Longtime User
Thanks @klaus. I finished up with a solution that created a new line each time there was a lead change, with the color alternating between red and blue. The code may not be as efficient as it could be:

B4X:
        Dim leadTmp As String = "0"
        Dim leadChangeNo As Int = 0
        Dim leadChange, positiveLead, flagLead As Boolean = False
        Dim Red As Boolean
        For r = 0 To tv1.Items.Size - 1
            tv1.SelectedRow = r
            Dim ap1 As AnchorPane = tv1.SelectedRowValues(0)
            Dim lbl1 As Label = ap1.GetNode(0)
            Dim ap2 As AnchorPane = tv1.SelectedRowValues(4)
            Dim lbl2 As Label = ap2.GetNode(0)
           
            'Determine if lead is positive or negative
            If lbl2.Text > 0 Then positiveLead = True
            If lbl2.Text < 0 Then positiveLead = False
           
            'Flag if there is a lead change - the first score will be a lead change
            If r = 0 Or positiveLead <> flagLead Then
                leadChange = True              
            Else
                leadChange = False
            End If
            flagLead = positiveLead
           
            'Determine if initial line is red (positive lead) or alternatively blue
            If r = 0 Then
                If positiveLead = False Then
                    Red = True
                Else
                    Red = False
                End If  
            End If
           
            'Add chart line of appropriate color when there is a lead change
            If leadChange = True Then  
                If Red = True Then
                    XYChart1.AddYXLine("Lead", xui.Color_Blue, 1)
'                    Log("Adding blue line")
                    Red = False
                Else
                    XYChart1.AddYXLine("Lead", xui.Color_Red, 1)
'                    Log("Adding red line")
                    Red = True
                End If
                leadChangeNo = leadChangeNo + 1
            End If
           
            'Add data points to line, incl start of new line and end of old line when there is a lead change
            If r = 0 Then
                XYChart1.AddYXPoint(leadChangeNo - 1, MinSecToDecMins(lbl1.Text), 0)
            Else
                If leadChange = True Then XYChart1.AddYXPoint(leadChangeNo - 2, MinSecToDecMins(lbl1.Text), leadTmp)
                XYChart1.AddYXPoint(leadChangeNo - 1, MinSecToDecMins(lbl1.Text), leadTmp)
            End If
            XYChart1.AddYXPoint(leadChangeNo - 1, MinSecToDecMins(lbl1.Text), lbl2.text)
           
            'Save the lead so it can be used as a start or end point
            leadTmp = lbl2.text
        Next

but it essentially gives the result I was after:



So not just two lines, but as many as there are lead changes.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
So not just two lines, but as many as there are lead changes.
You are right, it will not work with only two lines.
Because when there are missing values, a line is drawn between the last point and the next point.
 

Lakhtin_V

Active Member
Licensed User
Longtime User
Yes.
But you need to convert the values to Doubles and fill the chart.
Maybe the xGraph library is better suited for this purpose.
I have never done a WAV file format conversion. Can you suggest some way or example on how to prepare WAV file for processing by xGraph library
 

klaus

Expert
Licensed User
Longtime User
What kind of files do you want to display and what duration ?
Be aware that with a sample rate of 44100 Herz you get a lot of samples.
The xGraph like the xChart libraries are not designed to manage that amount of samples.
You would need to define the number of samples and any zoom function to fill the Graph from the file data.
This would be a project on its own.
I had begun one years ago, but never finished.
 

Lakhtin_V

Active Member
Licensed User
Longtime User
I was hoping to study a recording of 5-10 seconds long on a timeline with a minimum recording quality, for example, 22Khz. For my project, it is desirable to be able to work with an accuracy of 1/100 of a second. To identify the maximum point of the audio signal with reference to the timeline.
 

Lakhtin_V

Active Member
Licensed User
Longtime User
Do you have an example file ?
10 seconds is 220000 samples.
This will surement need either some compression or zooming.
It is important for me to know at what exact time the maximum signal was. The accuracy of determining the peak time is + -1/100 sec. It is desirable to be able to focus on the exact world time received from GPS. I will prepare a sample file in the coming days.
 

Lakhtin_V

Active Member
Licensed User
Longtime User
Do you have an example file ?
10 seconds is 220000 samples.
This will surement need either some compression or zooming.
It is important for me to know at what exact time the maximum signal was. The accuracy of determining the peak time is + -1/100 sec. It is desirable to be able to focus on the exact world time received from GPS. I will prepare a sample file in the coming days.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…