Android Question Question about xChart

D

Deleted member 103

Guest
Hi,

I am using the "xChart" class in one of my apps and have a display error in B4i.
The red line is displayed in B4a, but not in B4i, and I cannot explain why.
Somehow, the graphics update in B4i does not work.

In the class I added this function to show this red line.
Does the class already have such a function? Then my function would not be necessary.

B4X:
Public Sub DrawReferenzLine(refwert As Double)
    Dim mYAxis0 = Graph.Bottom + Scale(sY(0)).MinVal * Scale(sY(0)).Scale As Int

    xcvsGraph.DrawLine(Graph.Left, mYAxis0 - refwert * Scale(sY(0)).Scale, Graph.Right, mYAxis0 - refwert * Scale(sY(0)).Scale, Colors.Red, 2dip)
    xcvsGraph.Invalidate
End Sub

I call the function like this:
B4X:
Private Sub CreateTestChart
    Log("CreateTestChart")
    ...
    ...   
    BarChart1.DrawChart
        
    BarChart1.DrawReferenzLine(2)
End Sub

B4a-screenshot:
1611650350115.png


B4i-screenshot:
1611650418308.png
 
D

Deleted member 103

Guest
You will need to wait for Klaus answer. I guess that it is related to the chart being resized and redrawn. Try to call it in Page_Resize event (if it doesn't work then add Sleep(0)).
Thanks Erel, unfortunately I already tried it.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I tried it in the demo program and it works.

1611655908337.png


Which version of the xChart do you use.
I tested it with the version 6.6 and also 6.4.

Can you post the full code you use to generate the chart.

Your code doesn't work with B4J, colors must xui.Colors.
B4X:
xcvsGraph.DrawLine(Graph.Left, mYAxis0 - refwert * Scale(sY(0)).Scale, Graph.Right, mYAxis0 - refwert * Scale(sY(0)).Scale, xui.Color_Red, 2dip)

Does the class already have such a function?
No, only lines for the min, mean and max values on single bar charts.
 
Upvote 0
D

Deleted member 103

Guest
Hi Klaus,

many thanks for your response.

Your demo works for me too.
I start the chart in my app also Resize-Sub, but the red line is not displayed.
But if I start the chart from a button, then it works properly.

Well, the main thing is that it works.

No, only lines for the min, mean and max values on single bar charts.
Too bad, such a function would not be bad.
In my app it is necessary that a reference value can be displayed.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Upvote 0

klaus

Expert
Licensed User
Longtime User
Can you please test the attached class version 6.7?

I added two methods:
AddHorizontalLine(Value As Double, Color As Int, StrokeWidth As Int)
If a line with the value already exist, updates the Color And Stroke.
RemoveHorizontalLine(Value As Double)

Add the lines like this:
B4X:
    BarChart1.AddHorizontalLine(200, xui.Color_Red, 2dip)
    BarChart1.AddHorizontalLine(-200, xui.Color_Green, 2dip)
 

Attachments

  • xChart.b4xlib
    29.6 KB · Views: 88
  • xChart.bas
    190.6 KB · Views: 95
Upvote 0
D

Deleted member 103

Guest
Can you please test the attached class version 6.7?
Danke Klaus!
Now works perfectly.

And if you now add this variable with these two properties, then it's even better.
Why? Because sometimes you don't want to display the XAxisName but the legend name does.

B4X:
Sub Class_Globals
...
...
    'Neue Variable
    Private strLegendNameX As String
End Sub

Private Sub InitValues
...
...

'    If Graph.XAxisName = "" Then
'        txtX = "x = "
'    Else
'        txtX = Graph.XAxisName & " = "
'    End If
    If strLegendNameX = "" Then
        txtX = "x = "
    Else
        txtX = strLegendNameX & " = "
    End If
    
...
...
End Sub

Public Sub setLegendNameX(Name As String)
    strLegendNameX = Name
End Sub

Public Sub getLegendNameX As String
    Return strLegendNameX
End Sub

1611674423757.png
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I understand your case, it's evident that the X axis is a date and displaying the X-axis takes place.
But, I don't like this to add a new text variable to display and I am afraid that it would become confusing.
I could add a property to disable the display of the X-axis name.
 
Upvote 0
Top