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
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)).
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)).
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.
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)
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
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.