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

dlh_007

Member
Licensed User
通过MakeBMP函数,会生成如下图表:

B4X:
Private Sub CreateLineChart(Width As Int,Height As Int,YAxisName As String)
    ' Initialize the line data
    LineChart1.Width=Width
    LineChart1.Height=Height
    
    LineChart1.ClearData
    
    LineChart1.XAxisName = "s"
    LineChart1.YAxisName = YAxisName
    
    LineChart1.AddYXLine2(publicMod.GetLanguage(117), Colors.Red,2dip,True,"NONE",False,Colors.Red) '0 = random color
    LineChart1.AddYXLine2(publicMod.GetLanguage(118), Colors.Green,2dip,True,"NONE",False,Colors.Green)

    LineChart1.AddYXPoint(0,0,0)
    LineChart1.AddYXPoint(1,0,0)
    LineChart1.DrawChart
End Sub

private Sub MakeBMP(Width As Int,Height As Int) As B4XBitmap
    CreateLineChart(Width,Height,"N")
    LineChart1.AddYXPoint(0,Rnd(1,8), Rnd(500,4000))
    LineChart1.AddYXPoint(1,7, 1500)
    LineChart1.AddYXPoint(0,Rnd(1,8), Rnd(500,4000))
    LineChart1.AddYXPoint(1,8, 1500)
    LineChart1.DrawChart
    Return LineChart1.Snapshot
End Sub
 

klaus

Expert
Licensed User
Longtime User
The xChart library has been updated to version 9.4.

Added SetZoomSteps(SmallStep As Int, BigStep As Int) method
Added ZoomLeftButtonClick, ZoomRightButtonClick, ZoomLeftAreanClick and ZoomRightAreaClick events
Added ZoomSmallStep, ZoomBigStep, ZoomBeginIndex, ZoomEndIndex and ZoomNbVisiblePoints properties read only
Amended multiple zoom problem
Amended GetCursorIndex when zoomed
Added XZeroAxis and XZeroAxisHighlight properties
Only the xChart.b4xlib and xChart.xml files have been updated.
 

klaus

Expert
Licensed User
Longtime User
The xChart library has been updated to version 9.6.
Amended zoom problem.
Amended AutomaticScales with only one point.
Files updated in post #1, only the xChart.b4xlib and the xChart.xml files.
 

klaus

Expert
Licensed User
Longtime User
The xChart library has been updated to version 9.7 in the first post.
Added a warning for the RemovePointData method
Changed getNbPonts to Return Points.size
Added ZoombarEnabled property, code only not in the Designer
Only the xChart.b4xlib and xChart.xml files have been updated.
 
Hi,
Can it be possible to have Dynamic Zoom Scroll Bar? i.e. We are plotting real-time chart but instead of making line graph massive when there is lot of data after some time, there should be a scroll bar below the graph to see the old graph and otherwise the graph windows should be on predefined zoom level. Thanks.
 

klaus

Expert
Licensed User
Longtime User
It is possible.
It needed a small change in the xChart library in the SetZoomIndexes routines.
When you scroll during the acquisition, at the next input the zoom goes to the end.

Attached you find a small B4XPages project, only B4J has been used, demonstrating the possibility and the new xChart.b4xlib file.

EDIT: Files have been removed, new ones in post #657.
 
Last edited:
Thanks for quick solution. I tested the zoom function which is basically ok as needed concept but need fine tuning. At the moment when plot data grows sufficiently, the scroll bar cursor Stucks in between even we move it, it come back.
Also at that time the chart lines only show their pointers circle or square on the left edge of the chart and no complete lines to right edge. If we move the scroll bar cursor to left, the old chart appears but we leave the cursor, the chart blanks with only pointer on the left edge of the chart, showing current values.
At this time only X-Axis shows time stamp on first position of the X-Axis start zero position and sometimes shows one more time stamp on the right side of the chart. So initially to fine tune following a couple of suggestions should be consider. Thanks.

1- Scroll bar should be visible always (enable/disable option is for if anybody need or not). At start it should be full until the basic limit of visible data is reached. i.e. if we need to plot 20 readings then it should be going smaller with every data and aligned to right side.

2- If plot data grows huge the scroll bar cursor should have minimum size and should not be shrink any more with more data.
 

klaus

Expert
Licensed User
Longtime User
1- Scroll bar should be visible always (enable/disable option is for if anybody need or not). At start it should be full until the basic limit of visible data is reached.
I will not add this, because it is too specific, only for your case.
No user would like to see a scrollbar for nothing.

i.e. if we need to plot 20 readings then it should be going smaller with every data and aligned to right side.
This is already the case.

2- If plot data grows huge the scroll bar cursor should have minimum size and should not be shrink any more with more data.
I will look at this.
How many data do you expecting ?

The management of the input of new data and moving the zoom cursor at the same time would be very difficult.
This management is done outsides the xChart library.
The chart is redrawn for each new incoming data and also for each zoom change, so which one has priority.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
2- If plot data grows huge the scroll bar cursor should have minimum size and should not be shrink any more with more data.
This is already the case. The minimum width was set to 10dip.
I have increased it to 15dip for the next update.
 

klaus

Expert
Licensed User
Longtime User
The attached project does what you expect.
The only point is that the zoom bar is only displayed when the minimum number of data is reached.
At the beginning when the zoom bar is displayed, the zoom is disabled.
When you check the Checkbox, the zoom is enabled and the zoom remains where it is, the new data is of course added.
The management for the zoom is in the main program not in the xChart library.
 

Attachments

  • DynamicZoom1.zip
    109.4 KB · Views: 85
  • xChart.b4xlib
    46.5 KB · Views: 89
Thanks for update and it works as we need it. Actually as I need it to draw voltage current chart real-time, but also I wanted to have many versatile functions in this chart as an asset of B4X. I am switching from classic VB6 where I have very nice such a plot/trend/chart OCX which does all things efficiently which I wanted in B4J to be excellent tool.
Now scroll bar is also working good but ReadingsMax is confusing a bit. i.e. if we want to show chart for 4 hours with data every 5 seconds then what ReadingsMax can be set?
 

klaus

Expert
Licensed User
Longtime User
Now scroll bar is also working good but ReadingsMax is confusing a bit. i.e. if we want to show chart for 4 hours with data every 5 seconds then what ReadingsMax can be set?
4 hours = 240 min = 14400 sec, and every 5 seconds therefor, 14400 / 5 = 2880
ReadingsMax = 2880
If the number of readings exceeds 2880 the first data is removed and the total number of readings remains at this value and you will only see the data of the last 4 hours, the older values are deleted.
 
I tried it in your example to increase the ReadingsMax to 3000 but it seems problematic. ReadingsToShow = 20 and ReadingsMax = 3000 and I check Allow Zoom Cursor and scroll back, it only shows 1 minute 30 seconds chart!!! and sometimes less or more!!! Can you check it and what is maximum ReadingsMax value???
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…