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

klaus

Expert
Licensed User
Longtime User
the IDE library manager still lists 8.10 as the latest available version
I had changed the name from ClearPoints to ClearYXPoints, because I had a problem.
But then the problem was solved and now I have set it back to ClearPoints.
The files have been updated in the first post.

Does the library provides a Pinch2Zoom function for a lineChart?
That would be awesome
No, this is not supported.
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
I had changed the name from ClearPoints to ClearYXPoints, because I had a problem.
But then the problem was solved and now I have set it back to ClearPoints.
since I’ve already changed my code, are the 2 subs equivalent, or else what are the respective use cases?
 

klaus

Expert
Licensed User
Longtime User
The xChart Class and b4xlib have been updated to Version 8.5.

Added WATERFALL chart and the WaterfallTotalBarColor property.
The CandleDecreaseColor and CandleIncreaseColor properties were changed to DecreaseColor and IncreaseColor.
These properties are also used with WATERFALL charts.
 

Peter Simpson

Expert
Licensed User
Longtime User
Hey hey hey hey hey slow down Klaus, take it easy and slow down. You're updating and releasing new charts like they are going out fashion lol

Anyway nice one and thank you ?
 

klaus

Expert
Licensed User
Longtime User
Don't worry, I will slow down.
I think that the most used charts are now in the class.
I have in mind a xChartLite class, with a few simple basic charts (Pie, Bar, Line), not all users need the 'full' and 'heavy' version.
But, this is only a thought for now. The difficulty is what to keep in the class and what is superfluous.
 

AnandGupta

Expert
Licensed User
Longtime User
I think what you mentioned (Pie, Bar, Line) is standard as far as lay man (me included) needs and understand.
Rest goes beyond my knowledge and requirement. A lite version may make our apps smaller.

But THANK YOU ? for all your efforts.
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
I think the effort of maintaining 2 separate versions is justified only if the size of an app with only the basic charts is significantly less than a full one
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello Klaus,
I have an idea, it's not really that important but I think that it could help developers with displaying chart values externally.

xChart allows you to auto generate 2 subs (see screenshot at the bottom). My idea is to simply add a third xChart sub with the following signature
B4X:
     MyChart_ChartValues(Values As Map)

The map would store the chart values which in turn would allow developers to set MyChart.DisplayValues = False, thus developers could then display the chart values separately in labels that are not in the chart area but outside of the chart area.

Current autogenerated xChart signatures



Thank you

Peter...
 

klaus

Expert
Licensed User
Longtime User
Hi Peter,
Adding a new event like your suggestion is not that easy because the data structure is different for different chart types.
This means that different Maps should be defined depending on the chart type.
And I am sure that not many users need it.

Anyway, what you want to do is currently already possible with the CursorTouch event.
MyChart_CursorTouch (Action As Int, CursorPointIndex As Int)
Action is the same as in the standard Touch events.
0 = DOWN
1 = UP
2 = MOVE

CursorPointIndex is the index of the Point where the cursor is positioned, the cursor snaps onto the point when moving.
While I am writing this I remark that the name CursorIndex is not the best, I will change it to CurrentPointIndex in the next xChart update.
To use it, you need to know the data structure in the xChart library.

There are two data lists:

Items: hold items of the different charts like: Bar, Line etc. in a specific data Type: ItemData
Some of the parameters are:
Name
Color
StrokeWidth
etc.

Points: hold point data in a specific data Type: PointData
X: value on the X axis, String
YArray(): array of Y values, one value per item, Double
For multi Line, multi Bar or StackedBar charts the YArray holds the Y values for each Item.

Example for a Candle chart, the Candle chart has no items only points :
The names of the Labels are self explanatory which index of the YArray holds which value.
B4X:
Private Sub Candle1_CursorTouch (Action As Int, CursorPointIndex As Int)
    Select Action
        Case 0, 2    'DOWN or MOVE
            Private PD As PointData
            PD = ChartTickerPrice.Points.Get(CursorPointIndex)
            lblDate.Text = PD.X
            lblOpen.Text = PD.YArray(0)
            lblHigh.Text = PD.YArray(1)
            lblLow.Text = PD.YArray(2)
            lblClose.Text = PD.YArray(3)
            lblVolume.Text = ChartTickerPrice.NumberFormat4(PD.YArray(4), 2, False)
        Case 1
            lblDate.Text = ""
            lblOpen.Text = ""
            lblHigh.Text = ""
            lblLow.Text = ""
            lblClose.Text = ""
            lblVolume.Text = ""       
    End Select
End Sub
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello Klaus,
Thank you for the fast response, now that you've explained it to me, it does make complete sense. Also thank you for the example too.

Anyway, what you want to do is currently already possible with the CursorTouch event.
MyChart_CursorTouch (Action As Int, CursorPointIndex As Int)
Action is the same as in the standard Touch events.
0 = DOWN
1 = UP
2 = MOVE


Peter...
 

klaus

Expert
Licensed User
Longtime User
The xChart Class and b4xlib have been updated to Version 8.8.
Added a new property: CandleDisplayVolume, False by default
Added a new method: AddCandlePoint2 including the Volume parameter
Renamed CursorIndex to CursorPointIndex in the CursorTouch event routine
Added DisplayCursor property to allow to display the cursor without displaying the values, False by default
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello Klaus,
As usual you've done an excellent job updating the B4X xChart library.

I've quickly created a comparison between the xChart Candlestick chart with Volume and the Yahoo finance chart with Volume for the trading symbol GOOG. As you can clearly see the xChart information is spot on with Yahoo information, but personally I'm really impressed with the optional Volume chart. Seeing the trading Volume chart (at the bottom) is extremely important if you're a trader as this allows you to view the volume of shares traded in contracts/stocks traded in futures/options compared to the candlestick information and time period.

This is excellent Klaus, cheers ?

B4X xChart Candlestick chart with Volume - Symbol (GOOG)


Yahoo finance Candlestick chart with Volume - Symbol (GOOG)




xChart Candlestick chart, off chart values in labels at the bottom of the screen.
Apple Inc. - Symbol (AAPL) with ticker values shown off the chart. The sub you posted above works 100% perfect Klaus, thank you...




Thank you

Peter...
 
Last edited:

klaus

Expert
Licensed User
Longtime User
The xChart library has been updated to Version 8.9
Amended problem with min bar width for STACKED_BAR charts.
Only the xChart.b4xlib, xChart.bas and xChart.xml files have been updated.
 

klaus

Expert
Licensed User
Longtime User
The xChart library has been updated to Version 9.0
Added the DisplayValuesOnHover property: Show values when hovering with the cursor over a chart; valid only for B4J.
Only the xChart.b4xlib and the xChart.xml file have been updated.
 

Tecuma

Member
Licensed User
Hello, I have a question about AddLineMultiplePoints.
When I see the examples I can see that I have to use an array. AddLinePointData is not working.
What happen when I do not have a value for every element in the array?

Background.
I have my values in a DB. For a day I save several values divided by a tag. E.g.
2022-07-01 01 Private
2022-07-01 02 Private
2022-07-01 01 Work

I want to draw a line for each tag (Private, Work). I have 2 values for Private and 1 value for work.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…