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

Mahares

Expert
Licensed User
Longtime User
The xChart Class has been updated to version 2.9 in the first post.
Good day:
I tied to run the sample project in post #1 by @klaus after he updated the class to 2.90 but encountered a couple of crashes.
When executing the Sub CreateSingleBarData a couple of crashes occur when i =0 to 41 and when i=0 to 45. See error messages below:

When: For i = 0 To 41
B4X:
Error occurred on line: 1536 (xChart)
java.lang.IllegalArgumentException: width and height must be > 0
                at android.graphics.Bitmap.createBitmap(Bitmap.java:969)
                at android.graphics.Bitmap.createBitmap(Bitmap.java:948)
                at android.graphics.Bitmap.createBitmap(Bitmap.java:915)
                at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeMutable(CanvasWrapper.java:654)

When; For i = 0 To 45
B4X:
Error occurred on line: 1530 (xChart)
java.lang.NegativeArraySizeException: -100
                at b4a.example.bitmapcreator._initialize(bitmapcreator.java:2162)
                at b4a.example.xchart._drawbars(xchart.java:2871)
                at b4a.example.xchart._drawchart(xchart.java:475)
 

klaus

Expert
Licensed User
Longtime User
Hi Mahares.
Thank you for reporting the bug!
The problem was that, with many bars, the bar width became 0 in the first case and negative in the second case.

Can you please test the attached xChart.bas module.
Version 3.0, I amended the error above and improved the bar width calculation.
If the bar width is too small, a message is displayed in the Logs and no chart is drawn.



EDIT: Removed the zip file, last version in the first post.
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
Can you please test the attached xChart.bas module.
Bon apres-midi klaus:
With your new revision of xChart 300, it works really well. I even tested it with 90 (45x2) points as upper limit and it still drew the graph, although you would not normally want that many bars anyway.
One more very minor issue although it may not be an issue in your estimation:
when you type BarChart2.IncludeValues the intellisence shows string, although it is accepting false or true
Example: BarChart2.IncludeValues=True
Thank you for constantly thriving to improve your products no matter how taxing they are.
 

klaus

Expert
Licensed User
Longtime User
One more very minor issue although it may not be an issue in your estimation:
It is an issue for me . Thank you for reporting it.
Done for the 'official' update, I'll keep the same version number.
 
Last edited:

jmon

Well-Known Member
Licensed User
Longtime User
Hello, Thanks a lot for sharing this library. It's very good work.

I have 1 error, and I didn't find how to fix it:
Error occurred on line: 1955 (xChart)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
In B4A, when I set my xChart to "Pie" and set the legend to "BOTTOM". It's caused by this line:
B4X:
y = y0 + 1.6 * box * Legend.LineNumbers.Get(i)
"Legend.LineNumbers" is always size = 0 in my code

Thanks!
 
Last edited:

jmon

Well-Known Member
Licensed User
Longtime User
Can you please test the attached Class Module.
It works, now I can get the legend under the pie chart, but the pie chart doesn't occupy the whole space anymore:

And that also broke the "TOP_RIGHT" positioning:


Thanks for your support
 

Peter Simpson

Expert
Licensed User
Longtime User
Hello @klaus,
I was just wondering how difficult do you think it would be to print these carts to a printer?

I'm just asking as I have a B4J project that I'm looking at creating but I might need to print some charts to a physical printer and not just view the charts on the device screen. I know that devices have to have at least one print service installed and running on them, for example in my case I have both Canon and Samsung print services running on my Android devices for my WiFi network printers. I'm just wondering as that might be something that B4X users (including myself) would want to manipulate in the future.

I presume that if printing was at all possible that one would have to print the B4X canvas itself in some fashion, but I don't really know and that's why I was wondering.

Thank you.

Peter...
 
Last edited:

klaus

Expert
Licensed User
Longtime User
I have never used any printer with Android.
Can you print a Bitmap ?
I had a look at the Printer object in the Printing library, it has a PrintBitmap method.
You can get the chart bitmap with xChart1.Snapshot, it returns a B4XBitmap.
Never tested.
 

Peter Simpson

Expert
Licensed User
Longtime User
Absolutely perfect @klaus, nice one.
I already had the Printing Library in this particular project for printing PDF files via the PrintPdf method, but I never noticed the PrintBitmap method in the same library. I also didn't realised that you had the Snapshot method in your class, I must be going blind.

All I did was set the chart colour to White (it was Light Gray) and I then added the following three lines of code after the DrawChart method.
B4X:
Dim PrintChart As Printer
    PrintChart.Initialize(Null)
    PrintChart.PrintBitmap("Mix Count Chart", MixCountBarChart.Snapshot, True)

After reading your response it only took about 8 minutes to get the following results.

Screenshot: Bar chart on my tablet


Screenshot: Select the wireless printer on my WiFi network


Photograph of A4 paper printout


Edited: Uploaded smaller screenshots and photo.

Thank you...
 
Last edited:

klaus

Expert
Licensed User
Longtime User
If you like, you can add an outer frame to the chart with:
xChart1.DrawOuterFrame = True
The default value is False.

Which version of the chart class do you use?
I saw on your chart that the Y axis name is overlapping the Y scale.
I have in mind that I amended this, perhaps there is still a problem.
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Which version of the chart class do you use?
I saw on your chart that the Y axis name is overlapping the Y scale.
I have in mind that I amended this, perhaps there is still a problem.

Good morning Klaus,
The above is an older app that I created for a client. As I knew that I had used xChart in that particular app I quickly tested the PrintBitmap method with it, I then printed the chart and posted the results above. It was only afterwards that I realised you had updated your xChart class, I then upgraded the class in all my apps.

The images in post #136 were done using xChart V2.4, but I can confirm 100% that xChart V3.1 DOES NOT overlap the Y axis text, so all is good here.


Thank you again...
 
Last edited:

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello @klaus ;
I added your class in my project. and I prepared shor sample for my qustions.

The xChart in Scroollpane. And I changed width and heght. It's controlled with code like under below.
But when if I have a lot variable on chart, chart has en error "Bar width = too small !!! Drawing of Bar chart skipped"
I cannot understand it. why it has problem?

55dip and ups is work, 40 dip -30dip not works(on page-3). But other samples works(Page-1 &page-3).
B4X:
ScrollPane_DurusOzet.InnerNode.PrefHeight=TableView_DurusOzet.PrefHeight+20+m.Size*55dip+50
I want bar size more small.









Note: "STACKED_BAR" has not Y axis values. I showed with small updated. People need show axis values. can you update your class.

 

Attachments

  • charttest.zip
    74.8 KB · Views: 350
Cookies are required to use this site. You must accept them to continue using the site. Learn more…