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

klaus

Expert
Licensed User
Longtime User
The xChart Class has been updated to version 3.6 in the first post.
Amended wrong results during the first drawing, Added Sleep(0) in Base_Resize
Amended scales for the YXChart type
Amended some minor bugs
Amended scales problem with manual scaling


New
The class does now exist as a b4xlib, xChart.b4xlib file attached with xChart.xml file for the help.
You need to copy both files to the AdditionalLibraries folder for each product!
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Hell @klaus,
I tried moving the code as suggested too

B4X:
Sub MainForm_Resize(Width As Double, Height As Double)
    ' your code
End Sub

but still no joy.

As I said previously, the Sleep(0) that you added I've just commented it back out and everything is working as it did before. I only use the bar and line charts, and it only effects the Chart.Snapshot function so no worries.

Thank you...
 

klaus

Expert
Licensed User
Longtime User
Unfortunately, I cannot reproduce your problem.

Can you please try the attached version of the xChart class?
I added a DrawingFinished event in the class.
In the main code use an event routine like this:
B4X:
Private Sub YourBarChart_DrawingFinished
    ' your snapshot code
End Sub
Replace YourBarChart by the name of your xChart class.

EDIT: removed the file, it has been updated in the first post.
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User

Hello Klaus,
Yesterday I spent too many hours trying to code around the new Sleep(0) which was added, I finally got around the issue but with a major issue, so I went back to commenting out Sleep(0), I've spent way too much time on something so simple.

You always needs to resize the chart before creating a snapshot (I can create a copy of the chart and do it that way but I still have issues). After taking the snapshot I set the chart back to its original size. Doing this means that no matter what the screen resolution is or OS (Windows or Mac), the Snapshot will always be the perfect size for printing (in my case on A4 paper size), always redraw the chart after resizing it but before the snapshot. You saw from the PDF I showed you that the printout is absolutely perfect with no stretching of text, that result is the same nomatter what screen resolution or OS is being used.

Without using Sleep(0) you cannot see the chart resize before the snapshot, but with the Sleep(0) you can see the chart resize quickly (before the snapshot) and then go back to its original size again. I spent hours yesterday trying to get around the Sleep(0), so I went back to a backup from the previous day, I've spent way too much time on it, I can't give my application to my client with visibly resizing charts which has been happening since adding Sleep(0), it does make sense though when using Sleep(0).

Your xChart class is excellent but since adding the Sleep(0) I've not been able to either prints charts correctly or when I do print a chart correctly you can clearly see the chart change size as it should do but you couldn't see it happening before adding Sleep(0).

I'll test your updated xChart tomorrow, I'll let you know my findings. But as I said previously, I've just commented out the sleep(0) and all the charts in the application prints perfectly as they did previously and you can't see the chart quickly resize and go back again, it does make sense why you can see it happen with Sleep(0) added though.

Thank you and I'll let you know tomorrow how I get on.

By the way, sorry for not posting an example but I've been in a meeting all day with a potentially new client.
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Hello @klaus,
I was just thinking it might be a good idea to be able to have the mean line value switchable as either an integer or a double. The case below is showing a double but in theory that not really be necessary and all mean line values in this chart could just be an integer, so 2268.42 would just read 2268.



Just a quick thought and not really that important.

Thank you...
 

klaus

Expert
Licensed User
Longtime User
You can already set the number format for the mean line value!
Use simply:
xChart.SetBarMeanValueFormat(1, 0, 0, False)
sets a custom numberformat for the bar mean line value, values like NumberFormat2.

I am still looking for the resize problem.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Hi Peter,
I had a deep look at your problem.
The attached project works.
I added a second xChart object in the layout which is outsides the screen.
It's dimensions are set in the Designer directly to the A4 values.

All the properties you are setting in the code can be set directly in the Designer.

The problem in your current project is the width and height changes which redraw the whole chart.
 

Attachments

  • ChartPrintTestNew.zip
    23.1 KB · Views: 516

Peter Simpson

Expert
Licensed User
Longtime User
Hello @klaus,
I know that you probably have better things to do.

Okay, I've seen what you've done and yes thank you it works perfect on both PC and Mac. I hope that you didn't spend too much time on it, I spent hours on it and got absolutely nowhere.

The reason why I set the properties in code is simply because I have all the setting in code already, so I don't really use the designer properties. But as you've mentioned it, I'll set it all up in my current project later.

Thank you again, you've been a great help...
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @klaus,
I was just wondering if you could look at the chart Y value and what happens when the value goes past 5000. I also noticed this last month too where when the value goes past 5000 the chart scale jumps up to 10000, I would have expected 6000 or maybe 7000 at a push, I was just wondering what would happen if the value went past 10000, I'm presuming that the Y value would go to 20000 and not 11000 or 12000 at a push.

There's unwanted space between the top of the bar dated 22nd and the top of the actual chart.
As you know, all my Android, Windows and Mac applications prints the charts, the problem is that it looks rather strange when printed with such a lot of wasted space at the upper half of the chart.



Thank you...
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Hi Peter,
I understand your concern.
I am used to have 'simple' scale values and prefer them, I had used a lot of measurement devices like oscilloscopes etc, which had this kind of scales and also created lots and lots of graphics with these scales.
And it is easier to estimate intermediate values with 'simple' scales.
But many users don't realy care about the scale details.

Therefore, I added a new property: ScaleValues, which is a string with the values separated by an exclamation mark.
The default ScaleValues: 1!2!2.5!5!10
Another is selectable in the Designer: 1!1.2!1.5!1.8!2!2.5!3!4!5!6!7!8!9!10
And the user can define its own custom property in the code.

Can you please test the attached file?
You need to run the Designer to make the property active and select the second one or define yours in the code.
 

Attachments

  • xChart.bas
    99.1 KB · Views: 425
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Hello @klaus,
Sorry for the long delay, I've just turned my laptop on so I've only just been able to test your updated chart, and here are the results.

Perfect as usual


My client will be happier now when he can print individual item sales charts on his Mac for his staff.

Thank you...
 
Last edited:

klaus

Expert
Licensed User
Longtime User
The xChart class has been updated to version 3.8 in post#1.
I added a new property: ScaleValues, which is a string with the values separated by an exclamation mark.
The default ScaleValues: 1!2!2.5!5!10
Another is selectable in the Designer: 1!1.2!1.5!1.8!2!2.5!3!4!5!6!7!8!9!10
And the user can define it's own custom property in the code.

You need to run the Designer to make the property active and select the second one or define yours in the code to change it.
 

Peter Simpson

Expert
Licensed User
Longtime User
Auto size not working correctly. I am using this method just like the xGauges class and adjusts pretty well.

Hello Scantech,
Just for the fun of it, I tried your code above using B4J with the demo code provided by Klaus in the first post. Every single example chart text look way off, text was drawing over the top of each other or text just was drawing way out of place, one the charts also had huge text.

I use three of the charts for a clients project, I also use xcharts for other clients projects using B4A and B4J, I've never come across any text auto scaling issues, not even on a Mac.

Can you give a specific example as you say 'Auto size not working correctly'?

I'm only asking as I intend on using xCharts for all future B4A and B4J projects and as far as I'm concerned xCharts is basically working perfect.

Cheers...
 
Last edited:

Scantech

Well-Known Member
Licensed User
Longtime User
Sorry I did not check b4i and b4j. I guess it's only good for b4a only. You can test Klaus example and mine you will see the difference in b4a.

Mine was tested on high resolution. I will test low resolution later on.

Klaus example with small width it will not adjust properly.
 
Last edited:

Scantech

Well-Known Member
Licensed User
Longtime User
Disregard my example above. Klaus method is ok. I was testing it at a very small scale and was wondering why the font size did not decrease any further. But it was too small you can bearing see any graphing.

My method works horribly even with b4a and i deleted the example.
 
Last edited:

Scantech

Well-Known Member
Licensed User
Longtime User
Found 1 issue with xChart with Scale(sY).Automatic = True and using Dynamics. You can see the photo attached. It only happens once every 5 seconds using numbers from 0 to 20000 and occurs with higher number range only (over 10000). I am using DynamicLines1.AddLinePointData



The value is always = 1.81899E-12

Update: here is a debug log happens in release mode more frequently.
In DrawYScale Event
Scale(sY).MaxVal: 16000.000000000004
- i: 8
Scale(sY).interval: 2000.0000000000002

In NumberFormat3 Event
Number: 1.8189894035458565E-12
MaxDigits: 6
lng: 0.25983016910473467
exp: -12
str: 1.81899E-12
mant: 1.8189894035458618
I have not figured it out yet. Im looking into CalcScaleAuto.
 
Last edited:

Scantech

Well-Known Member
Licensed User
Longtime User
Another issue. YZeroAxis = true and negative y axis text value is shown (-2000). Using rnd numbers from 0 to 20000. It does not occur right away. Sometimes i need to wait 30 seconds.


Update: You can duplicate it easily setting tmrDynamic.Initialize("tmrDynamic", 20). The issue occurs more rapidly with fast pace.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…