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

angel_

Well-Known Member
Licensed User
Longtime User
It is similar, it could serve, I'm looking for to show this equation, in log-log scale:

y = m / (x^n - 1)

m, n constants
 

Attachments

  • Chart.JPG
    71.8 KB · Views: 227

klaus

Expert
Licensed User
Longtime User
angel_
Can you please test the attached class.
I post the B4J project, the xChart.bas file is included, you can load it into your project and uncheck xChart in the Libraries Manager Tab, if you use it.
Logarithmic scales can only be used with LINE charts for the Y axis and with YX_CHART charts for both Y and X axes.
The lines in the bottom chart are defined with examples of your equation.



EDIT: 2020.02.11 Removed source code, it has been updated in post #1.
 
Last edited:

angel_

Well-Known Member
Licensed User
Longtime User
Is it posible to change the scale axis?, like chart2 with intermediate lines.
 

Attachments

  • chart1.jpg
    17.5 KB · Views: 222
  • chart2.jpg
    26.2 KB · Views: 219

klaus

Expert
Licensed User
Longtime User
Can you please test the attached project, I have not changed the version number.
You can set the number of intermediate lines in a decade for both axes with
YXChart1.ScaleYValuesLog = "1!2!5!7!10", standard value.
or
YXChart1.ScaleXValuesLog = "1!1.5!2!3!5!7!10", X specific value.

You need to run the Designer and close it to activate the new properties.
The image below shows in the bottom chart manual (user defined) scales.

 

angel_

Well-Known Member
Licensed User
Longtime User
I changed ScaleXValuesLog in the code:
B4X:
YXChart1.ScaleXValuesLog = 1!2!3!4!5!6!7!8!9!10!20!30!40!50!60!70!80!90!100
but it seems doesn' work

I changed #DesignerProperty: Key: ScaleXValuesLog... 1!2!3!4!5!6!7!8!9!10!20!30!40!50!60!70!80!90!100 and then I selected it in properties and it works like the picture, then same with ScaleYValuesLog.

But I think it doesn't work if I change the YXChart1.YMinValue:

B4X:
YXChart1.YMinValue = 10
 

Attachments

  • chart_2_1.JPG
    29.8 KB · Views: 214
  • chart_2_2.JPG
    54.6 KB · Views: 214

klaus

Expert
Licensed User
Longtime User
This is wrong:
YXChart1.ScaleXValuesLog = 1!2!3!4!5!6!7!8!9!10!20!30!40!50!60!70!80!90!100
This is correct!
YXChart1.ScaleXValuesLog = "1!2!3!4!5!6!7!8!9!10"
Only the lines in one decade must be given.
The string must begin with 1! and end with !10.
With the declaration above, it works also with:
YXChart1.YMinValue = 10


This does not yet work if you set:
YXChart1.YMinValue = 20
YXChart1.YMaxValue = 200

This will be amended.
 

angel_

Well-Known Member
Licensed User
Longtime User
I wrote:
B4X:
    YXChart1.ScaleXValuesLog = "1!2!3!4!5!6!7!8!9!10!20!30!40!50"
    YXChart1.ScaleYValuesLog = "1!2!3!4!5!6!7!8!9!10!20!30!40!50!60!70!80!90!100!110!120!130!140!150"
'    YXChart1.AutomaticScale = False
    YXChart1.XMinValue = 1
    YXChart1.XMaxValue = 100
    YXChart1.YMinValue = 20
    YXChart1.YMaxValue = 200

It works (see chart), but I had to hide these lines:
B4X:
Public Sub setScaleXValuesLog(ScaleXValuesLog As String)
'    If ScaleXValuesLog.StartsWith("1!") = False Or ScaleXValuesLog.EndsWith("!10") = False Then
'        Log("Wrong ScaleXValuesLog property")
'        Return
'    End If
    ScaleLog(sX).ScaleValues = ScaleXValuesLog
End Sub

Is it not possible to do this?
 

Attachments

  • Chart_3_1.JPG
    26.3 KB · Views: 215
  • Chart_3_2.JPG
    44.6 KB · Views: 212

klaus

Expert
Licensed User
Longtime User
Try the latest version below.

Please dont use definitions like this, these are too specific.
YXChart1.ScaleYValuesLog = "1!2!3!4!5!6!7!8!9!10!20!30!40!50!60!70!80!90!100!110!120!130!140!150"
Why do you want such close scales at the end and not in the other decades?
100!110!120!130!140!150"
Define ONLY the lines in one decade, this remains general.
YXChart1.ScaleYValuesLog = "1!2!3!4!5!6!7!8!9!10"




EDIT: 2020.02.11 Removed source code, it has been updated in post #1.
 
Last edited:

angel_

Well-Known Member
Licensed User
Longtime User
Perfect!! thank you for this great library
 

klaus

Expert
Licensed User
Longtime User
The xChart Class has been updated to version 4.4.

You need to open the Designer and close it to save the layout file to make the new properties active.
Added logarithmic Y scales for LINE charts
Added logarithmic Y and/or X scales for YX_CHART charts
Added ValuesShowPosition property, can be upper left and new also upper right
Version 4.3 2020.01.07
Improved Bar width calculation
 

Peter Simpson

Expert
Licensed User
Longtime User
The xChart Class has been updated to version 4.4.

Thank you @klaus,
As you already know, I use your charts for bespoke clients application, as I find this particular set of charts really a class above the rest and works on all B4X platforms.

Once again thank you for all your hard work and dedication to the cause, I'm going to download this new version now.

Pete...
 

klaus

Expert
Licensed User
Longtime User
I had the honor to (literally) see Klaus while he started working on this library.
Oh yes, I remember this memorable day almost two years ago when I had the honor to welcome Erel and his lovely family in my house.
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @klaus,
After updating the library I'm now seeing this message on the chart, please note that it happens when clear the chart date using .ClearData then I setup the chart again with .AddBarPointData .......... and finally CrtOrderItems.DrawChart, that is when I see the image below. Please note that the chart will populate 100% correctly with the data when I press the populate chart button, it's just when I clear the data and set it back up again in code I see this.

I've always ran this sub beforehand just to make sure that the chart are correct.
B4X:
'CLEAR THE CHART
Sub ClearChart As ResumableSub
    CrtOrderItems.ClearData
    CrtOrderItems.AddBar("y", 0Xff006db3)
    CrtOrderItems.AddBarPointData(0, 0)
    CrtOrderItems.GridFrameColor = XUI.Color_Transparent
    CrtOrderItems.GridColor = XUI.Color_Transparent
    CrtOrderItems.ScaleTextColor = XUI.Color_Transparent
    CrtOrderItems.ChartBackgroundColor = XUI.Color_Transparent
    CrtOrderItems.Title = ""
    CrtOrderItems.SubTitle = ""
    CrtOrderItems.YAxisName = ""
    CrtOrderItems.XAxisName = ""
    CrtOrderItems.DrawChart
  
    Return Null
End Sub



Thank you...
 

klaus

Expert
Licensed User
Longtime User
Well, I added some error messages.
And if the max and min values are equal to 0, now, you get this error message.
In my mind, trying to draw a chart with data value(s) equal to 0 is not useful.
You should remove this line:
CrtOrderItems.DrawChart
There is no need to draw the chart without data.

Why do you set all these properties for an 'empty' chart and draw it?
Especially adding a Bar for nothing and a 0, 0 Point?
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Why do you set a ll these properties for an 'empty' chart and draw it?
Especially adding a Bar for nothing and a 0, 0 Point?

The chart can be redraw x amount of times and printed in less than a minute, so I've always just set the parameters in code. I know that they can be set in the designer, but when I first started using this great XUI xCharts library, I found it a lot quicker setting it up by code rather than through the designer. I can read that code in just a few seconds and know at a glance what's happening. I can take it all out but I'm more than sure that I've then spend awful long time.

Actually, that screen shot also happens after cheating the

If I didn't add 0,0 it used to crash on me, probably for a logical reason though.

Ill take out the code and see what happens, I'll let you know later, I'll have to set it up via the designer, and there are a lot of setting in there Klaus

Thanks you.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
No need to necessarily set the properties in the Designer.
Leave your code as it is, but only remove CrtOrderItems.DrawChart and it should work.
I tested it in my demo program.
With CrtOrderItems.DrawChart, I get the same error as you, and without it it works!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…