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

Peter Simpson

Expert
Licensed User
Longtime User

That is looking excellent Klaus, thank you very very very much.
 

klaus

Expert
Licensed User
Longtime User
Hi Peter,
Can you please try this version:



The default orientation is still HORIZONTAL, backward compatibility.
For HORIZONTAL, if the text width is greater than the bar interval, the orientation is automatically set to VERTICAL.
For VERTICAL, if the text height is greater than the bar width, the text size is reduced to fit in the bar width. If the size is less than 10, the values are not displayed.

EDIT: 2019.01.15
Removed the file, updated in post #1.
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
This is excellent @klaus.
Below is a screenshot of one items orders before I print the chart using JavaFX8, printout looks fabulous.

This chart is from November 2018, but starting from this month (January 2019) all weekend orders will be added using the correct dates rather than Mondays date, thus there will be at least 8 more bars per month starting from this month.

By the way I like the fact that the chart will auto rotate the values if necessary.

B4J project for a client running on my MacBook Pro - Red is redacted information


Thank you...
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
The xChart Class has been updated to version 3.4 in the first post.
Added following properties: Subtitle, SubtitleTextSize, SubtitleTextColor
Added BarValueOrientation property
Amended transparent color

BTW I created a virtual chart with 31 days and 5 figure values, everything worked 100% perfect.

Nice work updating the chart with the subtitle and especially the auto (horizontal/vertical) direction for the values is especially good.

Thank you...
 

micro

Well-Known Member
Licensed User
Longtime User
Hi to all, excellent library but i need a help



I can not trace the two lines of reference, how can I draw them?
The central lines are the results of same operations.
Thanks
 

micro

Well-Known Member
Licensed User
Longtime User
This kind of lines cannot be drawn with the xChart class.
The data structure is not adapted for this kind of data.
There are missing points and two y values for a same x coordinate.

ok, it's like I thought.
An solution comes to mind?
Thanks
 

klaus

Expert
Licensed User
Longtime User
An solution comes to mind?

I had a closer look at your problem.
It is possible with the YXChart type.



The code:
B4X:
    YXChart1.ClearData
   YXChart1.AddYXLine2("Example1", xui.Color_Red, 2dip, True, "CIRCLE", False, xui.Color_Red)
    YXChart1.AddYXLine2("Example2", xui.Color_Blue, 2dip, True, "CIRCLE", False, xui.Color_Blue)
    YXChart1.AddYXLine2("Example3", xui.Color_Blue, 2dip, True, "CIRCLE", False, xui.Color_Blue)
    YXChart1.XScaleTextOrientation = "VERTICAL"
    YXChart1.ChartBackgroundColor = xui.Color_White
    YXChart1.GridFrameColor = xui.Color_Black
    YXChart1.GridColor = xui.Color_Gray
    YXChart1.TitleTextColor = xui.Color_Black
    YXChart1.ScaleTextColor = xui.Color_Black
    YXChart1.DisplayValues = False
    YXChart1.YScaleMaxValue = 50
    YXChart1.YScaleMinValue = -50
    YXChart1.XScaleMaxValue = 20000
    YXChart1.XScaleMinValue = 0

    YXChart1.AddYXPoint(0, 0, 0)
   YXChart1.AddYXPoint(0, 2000, 20)
   YXChart1.AddYXPoint(0, 4000, 35)
   YXChart1.AddYXPoint(0, 6000, 45)
   YXChart1.AddYXPoint(0, 8000, 30)
   YXChart1.AddYXPoint(0, 10000, 20)
   YXChart1.AddYXPoint(0, 12000, 5)
   YXChart1.AddYXPoint(0, 14000, -10)
   YXChart1.AddYXPoint(0, 16000, -20)
   YXChart1.AddYXPoint(0, 18000, -40)
   YXChart1.AddYXPoint(0, 20000, -30)

   YXChart1.AddYXPoint(1, 0, 10)
   YXChart1.AddYXPoint(1, 10000, 10)
   YXChart1.AddYXPoint(1, 10000, 20)
   YXChart1.AddYXPoint(1, 20000, 20)

   YXChart1.AddYXPoint(2, 0, -10)
   YXChart1.AddYXPoint(2, 10000, -10)
   YXChart1.AddYXPoint(2, 10000, -20)
   YXChart1.AddYXPoint(2, 20000, -20)

    YXChart1.DrawChart
 

micro

Well-Known Member
Licensed User
Longtime User
It is possible with the YXChart type.
Hi Klaus
a small display problem

Why the test + and test-lines do not come up to 3000?
B4X:
TestChart.ClearData
    TestChart.XAxisName = "Testy"
    TestChart.YAxisName = "Testx"
    TestChart.AutomaticScale = True
    TestChart.AddYXLine2("Test", xui.Color_Red, 2dip, True, "CIRCLE", False, xui.Color_Red)
    TestChart.AddYXLine2("Test+", xui.Color_Blue, 2dip, True, "CIRCLE", False, xui.Color_Blue)
    TestChart.AddYXLine2("Test-", xui.Color_Blue, 2dip, True, "CIRCLE", False, xui.Color_Blue)
    TestChart.XScaleTextOrientation = "VERTICAL"
    TestChart.ChartBackgroundColor = xui.Color_White
    TestChart.GridFrameColor = xui.Color_Black
    TestChart.GridColor = xui.Color_Gray
    TestChart.TitleTextColor = xui.Color_Black
    TestChart.ScaleTextColor = xui.Color_Black
    TestChart.DisplayValues = False
    TestChart.YScaleMaxValue = 5
    TestChart.YScaleMinValue = -5
    TestChart.XScaleMaxValue = 3000
    TestChart.XScaleMinValue = 0

    'result
    TestChart.AddYXPoint(0, 0, 0)
    TestChart.AddYXPoint(0, 200, 0.4)
    TestChart.AddYXPoint(0, 400, 0.5)
    TestChart.AddYXPoint(0, 600, 0.5)
    TestChart.AddYXPoint(0, 800, 1.0)
    TestChart.AddYXPoint(0, 1000, 1.4)
    TestChart.AddYXPoint(0, 1200, 1.6)
    TestChart.AddYXPoint(0, 1400, -1)
    TestChart.AddYXPoint(0, 1600, -1.2)
    TestChart.AddYXPoint(0, 1800, -1.2)
    TestChart.AddYXPoint(0, 2000, -1.6)
    'rif1
    TestChart.AddYXPoint(1, 0, 1)
    TestChart.AddYXPoint(1, 500, 1)
    TestChart.AddYXPoint(1, 500, 2)
    TestChart.AddYXPoint(1, 2000, 2)
    TestChart.AddYXPoint(1, 2000, 3)
    TestChart.AddYXPoint(1, 3000, 3)
    'rif2
    TestChart.AddYXPoint(2, 0, -1)
    TestChart.AddYXPoint(2, 500, -1)
    TestChart.AddYXPoint(2, 500, -2)
    TestChart.AddYXPoint(2, 2000, -2)
    TestChart.AddYXPoint(2, 2000, -3)
    TestChart.AddYXPoint(2, 3000, -3)
  
    TestChart.DrawChart

Thanks

Edit:
sorry I just confused the x axis with y
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Can i get min value of chart width & height with active text size.
The text sizes are available as properties, but not the chart dimensions.
What exactly is the problem, do the bars become too small?
Can you post an example project showing your problem.

You could replace, in the class code:
Private Graph As GraphData
by
Public Graph As GraphData

And the in the main code:
B4X:
Private Graph As GraphData
Graph = BarChart1.Graph
Log(Graph.Left)
Log(Graph.Width)
Log(Graph.Top)
Log(Graph.Height)
 
Last edited:

Tayfur

Well-Known Member
Licensed User
Longtime User
The text sizes are available as properties, but not the chart dimensions.
What exactly is the problem, do the bars become too small?
Can you post an example project showing your problem.

Basiclly;
I setting all text size is "8". its fix.
and for example i need 50 bar.
I need All bars and bars label show

What is the minimum form width(X) for all bars and bar's tags to appear.
What is the minimum form height(Y) for all bars and bar's tags to appear.

I calculated it but not correctly. you knows it.
 

klaus

Expert
Licensed User
Longtime User
@Tayfur
The bar width is calculated in the InitChart routine in several steps.
The min bar width, without the values is 4 dip.
The min automatic text size is 10, below this size, the values are not displayed.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
@micro
I see it too now.
I need to look deeper why this happens.
It appears only at the first drawing. In my test program, the chart is drawn two times and it worked and I didn't see it
As an intermediate workaround, duplicate this line: TestChart.DrawChart
It will be amended in the next version with some other minor problems.
 

klaus

Expert
Licensed User
Longtime User
@micro
I found the solution. Will be amended soon in the first post.
Added Sleep(0) in the Base_Resize routine:
B4X:
Private Sub Base_Resize (Width As Double, Height As Double)
    xcvsGraph.Resize(Width, Height)
    xpnlCursor.Width = Width
    xpnlCursor.Height = Height
    xcvsCursor.Resize(Width, Height)
    Sleep(0)
    If Points.Size > 0 Or Graph.ChartType = "PIE" Or Graph.ChartType = "YX_CHART" Then
        DrawChart
    End If
End Sub
To make sure that the dimension adjustments are effectively done before drawing the chart.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…