B4A Library MPAndroidCharts - Various type of graphs / charts (Latest library V1.22 in post #1)

Johan Schoeman

Expert
Licensed User
Longtime User
If I change your code so that the same graph (in this case data from Readings2) is drawn on both tabs:
B4X:
    DrawChart("Readings2", mlc1)
    DrawChart("Readings2", mlc2)





...then the Y-axis labels of the graphs on both tabs appear the same - in this case without any decimal points.

If I change the code to:
B4X:
    DrawChart("Readings1", mlc1)
    DrawChart("Readings1", mlc2)
...then the Y-axis labels of the graphs on both tabs also appear the same - in this case with decimal points.





I can't see in the library any reason why they should be different. Are you passing the same type of values to both graphs? The graphs expect type float as the data. Could it be something related to the data that you pass?
 

beaker

Member
Licensed User
The 'Readings2' table is a copy of 'Readings1' with the data in columns 2, 3 & 4 multiplied by a factor of 38.66976 and column 5 multiplied by a factor of 88.57396. The data in Columns 1 & 6 are the same in both tables and the datatypes are the same in both tables.

In fact in my 'real' app there is only one table and the values depend on which units have been selected by the user. I only created this stripped down version with two tables to make the code simpler and hopefully easier for someone else to look through and track down the problem.

I've attempted to simplify things further and I've attached another version which doesn't get its data from a db table. Instead, the values are set in the code and I've chosen values similar to those in the original tables. There are also only three data points. Hopefully this will make it a bit easier to see what's going on. I've commented out the lines that set the maximum Y axis values so that the charts autoscale but the issue is present whether autoscaling is on or off.

Thanks for your time, it's greatly appreciated.
 

Attachments

  • MLC Y Axis Labels Issue non DB.zip
    33.2 KB · Views: 223

Johan Schoeman

Expert
Licensed User
Longtime User
Do you think it could be related to this issue?:
https://github.com/PhilJay/MPAndroidChart/issues/1497

I realise it's a different chart type but if they use some common code then maybe...?
I will have to dig into the code of the original Github project to see if I can track down the problem. The wrapper merely passes on the values from B4A to the original project to draw the graph with. Will see if I can find it.

The issue in your post above relates to the values that is displayed above the bars in the barchart. The problem you have must sit in the class that handles the Y-axis.
 

Johan Schoeman

Expert
Licensed User
Longtime User
From the Yaxis class...

/**
* Sets the formatter to be used for formatting the axis labels. If no formatter is set, the chart will
* automatically determine a reasonable formatting (concerning decimals) for all the values that are drawn inside
* the chart. Use chart.getDefaultValueFormatter() to use the formatter calculated by the chart.
*
* @param f
*/

I will add a formatter for the Y axis and post an updated library
 

beaker

Member
Licensed User
Ah yes, that looks like it's the culprit
While you're at it you couldn't take a look at the formatting for the markers could you? At the moment the decimal seperator is a comma and I can't see a way of changing this to a decimal point.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Ah yes, that looks like it's the culprit
While you're at it you couldn't take a look at the formatting for the markers could you? At the moment the decimal seperator is a comma and I can't see a way of changing this to a decimal point.
It shows decimal points on my devices - see various posting in this thread with pics showing a point. Don't know why yours is showing a comma. It must have something to do with the setup of your device (locale). I have seen this before with something that @BlueVision was doing. I was seeing a point and he was seeing a comma. Seems like everything changes once you cross the equator.....
 

beaker

Member
Licensed User
Ok, I'm in the UK so it should be a point.

I've knocked up a quick project (using some code found here on the B4A forum) to get the decimal seperator character from the system and it's returning a point and not a comma. I've also not come across any other instances where I get a comma instead of a point so I'm a bit confused at the moment

I've attached the project so you can see how I've gone about retrieving the decimal seperator character from the system.

Here's a screenshot showing it running on my HTC One M8:
 

Attachments

  • GetDecimalSeperator.zip
    7.7 KB · Views: 188

Johan Schoeman

Expert
Licensed User
Longtime User
Ah yes, that looks like it's the culprit
While you're at it you couldn't take a look at the formatting for the markers could you? At the moment the decimal seperator is a comma and I can't see a way of changing this to a decimal point.
New library files attached that sorts out the number of digits after the decimal point for the left and right Y-axis. Use it in your B4A code as follows:

B4X:
chrtChart.YaxisLeftNumberOfDigits = 1
chrtChart.YaxisRightNumberOfDigits = 3


 

Attachments

  • mpChartLib11Mar2016.zip
    353.6 KB · Views: 330
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
That's great, thanks very much Johan. I'll give that a go.
No need to thank me - just click on Like if it works. Or better, just donate GBP 100 000-00....
 

phukol

Active Member
Licensed User
Longtime User
hi guys im using this sub to generate data for my radarchart
B4X:
Sub loadRadar( strScore() As Float, strTitle As String,strCat() As String,intCount As Int)
    rc1.ChartDescription = strTitle
    rc1.ChartDescriptionColor = Colors.RGB(33,33,33)
    rc1.ChartDescriptionTextSize = 12  
    rc1.Width = pnl1.Width
    rc1.Height = pnl1.Height

    rc1.LegendShapeSize = 15.0
    rc1.setTheLegendPositionAndForm("BELOW_CHART_CENTER","CIRCLE")
    rc1.TheLegendColor = Colors.yellow
    rc1.TheLegendTextSize = 10.0  

    rc1.ValueTextColor =  Colors.RGB(33,33,33)
    rc1.ValueTextSize = 12.0
    rc1.YaxisTextSize = 10.0
    rc1.YaxisTextColor = Colors.RGB(33,33,33)
  
    rc1.Chart_1_Data = strScore
    rc1.XaxisTextColor = Colors.Cyan
    rc1.XaxisTextSize = 12.0
  
    rc1.ValueTextSize = 10.0
    rc1.ValueTextColor = Colors.Yellow  
    rc1.DrawGraphValues = False  
    rc1.GraphLineColor = Array As Int(Colors.Yellow, Colors.Red, Colors.Blue, Colors.Green, Colors.Cyan)
    rc1.GraphLineWidth = 2.0
    rc1.DrawFilled = True
  
    rc1.WebConcentricColor = Colors.Green
    rc1.WebRadialColor = Colors.Red
    rc1.WebAlpha = 200
    rc1.ConcentricLineWidth = 1.5
    rc1.RadialLineWidth = 2
    rc1.DrawWeb = True
  
    rc1.XaxisLables =  strCat

    rc1.MarkerToUse = 4
    rc1.setRadarData(1,8)
End Sub

however im encountering this error:
B4X:
java.lang.NullPointerException
    at mpandroidchartwrapper.radarChartWrapper.setRadarData(radarChartWrapper.java:302)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:747)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:267)
    at ed.reviewamigo.progress._loadradar(progress.java:1124)
    at ed.reviewamigo.progress._filltable(progress.java:695)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at ed.reviewamigo.progress.afterFirstLayout(progress.java:102)
    at ed.reviewamigo.progress.access$000(progress.java:17)
    at ed.reviewamigo.progress$WaitForLayout.run(progress.java:80)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5041)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
 

Johan Schoeman

Expert
Licensed User
Longtime User

I think it might be looking for the legend text. If you don't want to display the legend text then pass something like this:
B4X:
mrc1.LegendText = Array As String("", "", "", "", "")

It obviously depends on how many charts you want to display - my above code extract assumes 5 radar charts to be displayed. You have set all the below for the legend but not the legend text.....?
B4X:
    rc1.LegendShapeSize = 15.0
    rc1.setTheLegendPositionAndForm("BELOW_CHART_CENTER","CIRCLE")
    rc1.TheLegendColor = Colors.yellow
    rc1.TheLegendTextSize = 10.0
 

dusanpon

New Member
Licensed User
Longtime User
Hi,

First I would like to congratulate and thank you, Johan, on the great work with graphs.

Then I state my problem which is causing me troubles for two days already. I am a new user not knowing much about b4a, and I would like to use the graph. I can run the original example from Johan, and I can modify the example to do my work. Everything is fine here as long as I use the original software and modify it. However, when I start by writing my own program from scratch ("File" -> "New" + enable libraries from post 149) and using a copy of the source code from the Johans's original example, the thing does not work. All I get is an error message about resources not found; the line causing the error is "MultiLineChart1.SetLineData(2,50)".

I checked the forum and did not find any complains of this kind, therefore it must be my error. It looks to me as if something is not declared correctly in my version of the software, but declared correctly in the original software. Where to look for? Also: I am comming from a region with modified character set: decimal sign is a comma, not a dot, and alike. Could this be a problem?
Thanks in advance

Dušan, Slovenia
 

JNG

Member
Licensed User
Hi,

I am unable to configure Charts in my project and getting the following error pl advise

regards
 

Attachments

  • error.txt
    23.9 KB · Views: 173

Johan Schoeman

Expert
Licensed User
Longtime User
Look in the /Objects/res/drawable folder of this project https://www.b4x.com/android/forum/t...ry-files-in-post-149.58017/page-7#post-391641

There are files that you are missing from your project when you started a new project. Copy the files to your new project's /Objects/res/drawable folder and make sure once copied that you set them to READ ONLY before you compile your B4A project.
 

dusanpon

New Member
Licensed User
Longtime User

Thanks, but I had those files copied already.
I have tried once more to run your example from the post, and your example works fine. Then I created a new file and copied the complete source (lines 1 to including 225) from your example into the newly created file thus erasing the initial content of the newly created file. Then I copied the files from "drawable" folder into the corresponding place in the newly created project, made sure that they are "read-only" and activated the same libraries as are active in your example. No other changes were made.
Compiling of the newly created program works fine, no error messages there. There is, however, a warning message "Variable 'mlc1' was not initialized", this I have just noticed. Then the program starts on Samsung P6800, and crashes with the message: "Error occured on line 167 (Main)" and "Resources not found exception...."
I apologize for such stupid problems of mine, but no start is simple. Thanks for your help.
Regards

Dušan
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…