Hi there,
after trying to implement features I needed I decided to modify the fantastic xChart 10.0 from klaus to meet me needs.
I already talked back to klaus and he was so kind to encourage me to implement my own things.
I started with reviewing the xChart code and added small changes like implementing own touch info label color.
Using Google AI Studio ( I know but I have ideas but not the knowledge after all) I changed small parts of the xchart.b4xlib for my own use.
Then trying to implement pinch zoom I thought the library is to heavy weight and extracted the addline, addline2 part to implement my complete changes added as a class modul named LaborClass (name because of the app I code)
The first things I added then was AddLine3 sub
With this I was able to create the following view
Then I got brave and started implementing pinch zoom. I be honest, I told the AI what I wanted and reported errors/faults in heavy vibe coding sessions. It took some quota limits in free tier to finally get it to work.
I cannot recap all the changes but it was a constant forth and back, backups are the key !
The end result worked at last and I attach the code at the bottom so maybe someone with more knowledge knows what is really going on.
The pinch function is using java code to intercept and routes it through depending on singe pinch or two finger pinch.
A lot of code adjustments where done to show and enable the zoom bar.
All the code is in the LaborChart class no extra code needed
In the end it works
Still I want to share the result and hope someone is inspired by it.
Edit Version 1.2
I modified the ChartData, the respective routines in DrawGridV and also added some properties.
This allows to get a two colored sub title string
Use:
Version History:
Regards
Frank
after trying to implement features I needed I decided to modify the fantastic xChart 10.0 from klaus to meet me needs.
I already talked back to klaus and he was so kind to encourage me to implement my own things.
- The line graph should be able to react on min/max limits, and if crossed it should change color
- The touch info should be able to show the labels in colors that are free to choose. Not only the line color
- I wanted the two finger pinch zoom using the class in B4A on Android.
I started with reviewing the xChart code and added small changes like implementing own touch info label color.
Using Google AI Studio ( I know but I have ideas but not the knowledge after all) I changed small parts of the xchart.b4xlib for my own use.
Then trying to implement pinch zoom I thought the library is to heavy weight and extracted the addline, addline2 part to implement my complete changes added as a class modul named LaborClass (name because of the app I code)
The first things I added then was AddLine3 sub
B4X:
Public Sub AddLine3(Name As String, LineColor As Int, StrokeWidth As Int, PointType As String, PointFilled As Boolean, PointColor As Int, RefUnter As Double, RefOber As Double, AlertColor As Int)
If Items.IsInitialized = False Then
Items.Initialize
End If
If LineColor = 0 Then LineColor = xui.Color_RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
Dim ID As ItemData
ID.Initialize
ID.Name = Name
ID.Color = LineColor
ID.LegendColor = LineColor
ID.StrokeWidth = StrokeWidth
ID.PointType = PointType
ID.PointFilled = PointFilled
ID.PointColor = PointColor
ID.RefUnter = RefUnter
ID.RefOber = RefOber
ID.AlertColor = AlertColor
Items.Add(ID)
End Sub
With this I was able to create the following view
- The color of the line changes according to the min/max value and the touch info now is able to show values in color I wish
- All the other parts remained so if you use the class it follows the same parameters klaus uses in his library.
B4X:
chart_labor.AddLine3("Verlauf", MainColor, 1dip, "CIRCLE", True, MainColor, mCurrentRow.RefUnter, mCurrentRow.RefOber, AlertColor)
Then I got brave and started implementing pinch zoom. I be honest, I told the AI what I wanted and reported errors/faults in heavy vibe coding sessions. It took some quota limits in free tier to finally get it to work.
I cannot recap all the changes but it was a constant forth and back, backups are the key !
The end result worked at last and I attach the code at the bottom so maybe someone with more knowledge knows what is really going on.
The pinch function is using java code to intercept and routes it through depending on singe pinch or two finger pinch.
A lot of code adjustments where done to show and enable the zoom bar.
All the code is in the LaborChart class no extra code needed
In the end it works
Still I want to share the result and hope someone is inspired by it.
Edit Version 1.2
I modified the ChartData, the respective routines in DrawGridV and also added some properties.
This allows to get a two colored sub title string
Use:
two colored subtitle:
Dim zT As String = "Ziel: "
If mCurrentRow.RefUnter > 0 And mCurrentRow.RefOber < 99999 Then
zT = zT & mCurrentRow.RefUnter & " - " & mCurrentRow.RefOber
Else If mCurrentRow.RefUnter > 0 Then
zT = zT & "> " & mCurrentRow.RefUnter
Else If mCurrentRow.RefOber > 0 And mCurrentRow.RefOber < 99999 Then
zT = zT & "< " & mCurrentRow.RefOber
End If
' first part in green
chart_labor.Subtitle = zT
chart_labor.SubtitleTextColor = xui.Color_RGB(0, 180, 0)
' second part in red
If badCount > 0 Then
chart_labor.Subtitle2 = " (" & badCount & " Abweichung!)"
chart_labor.Subtitle2TextColor = AlertColor '
Else
chart_labor.Subtitle2 = ""
End If
Version History:
- Version 1.0 Initial
- Version 1.1 Added a helper sub ForceHideValues and modified Java code to prevent info panel to show when two finger pinch zoomed. Reset happens when all fingers are lifted.
- Version 1.2 Modified Type ChartData (Title As String, Subtitle As String, XAxisName As String, YAxisName As String, YAxisName2 As String, Left As Int, ............) to allow a two colored sub title string
Regards
Frank
Attachments
Last edited: