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

Similar threads

B4A Tutorial Android Charts Framework
B4A Library [B4X] [XUI] Pie Chart
Share My Creation Google Charts
B4A Tutorial Add Charts With Google Charts Service
B4A Tutorial [B4X] Smart String Literal

BarryW

Active Member
Licensed User
I have error now in ur library

It goes to PIE.PieData = 2 on debugger...

android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1166)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2395)
at android.content.res.Resources.getLayout(Resources.java:982)
at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.github.mikephil.charting.components.MarkerView.setupLayoutResource(MarkerView.java:39)
at com.github.mikephil.charting.components.MarkerView.<init>(MarkerView.java:29)
at com.github.mikephil.charting.components.MyMarkerView.<init>(MyMarkerView.java:27)
at mpandroidchartwrapper.pieChartWrapper.setPieData(pieChartWrapper.java:214)
at ne.itlection.v3.m_demo._crt_pie(m_demo.java:550)
at ne.itlection.v3.m_demo._test(m_demo.java:874)
at ne.itlection.v3.m_demo._activity_create(m_demo.java:373)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at ne.itlection.v3.m_demo.afterFirstLayout(m_demo.java:100)
at ne.itlection.v3.m_demo.access$100(m_demo.java:17)
at ne.itlection.v3.m_demo$WaitForLayout.run(m_demo.java:78)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
 

Johan Schoeman

Expert
Licensed User
Attached new library files and a B4A project. Made some mods to the library based on feedback received from @Mahares:
1. Setting the number of insignificant digits for each of the 5 possible line graph when the values are displayed inside the chart
B4X:
mlc1.GraphValueDigits = Array As Int(1, 1, 2, 3, 2)
2. Hide the legends of those line charts not being displayed when the legend colors must match that of the line colors
B4X:
mlc1.LegendTextColorsToMatchLineColors = True
3. Set the number of insignificant digits for the marker view - this will be applied to all the line charts in the graph (i.e not per line chart)
B4X:
mlc1.NoOfMarkerDigits = 3
The attached example uses inline Java code to display a toast message when the graph is saved (NOTE: it is saved to the default gallery of your device). Thus, you need to enable the B4A JavaObject library in the library tab of the IDE. When the graph is saved (in the attached example) it is also displayed in an imageview on top of the customview. Click on the imageview to return to the customview (see the toast message when you click on the button to save the graph)



1.png
 

Attachments

Yayou49

Active Member
Licensed User
Hi,

I Have a question regarding
mbc1.LegendText = ArrayAsString() and mbc1.ChartData = ArrayAs Float()

How to do with a dynamic array ???
I mean, if you don't know each time how many element are in your array list

Example for mbc1.ChartData :

Dim MyList1 as list
Mylist1.add(125)
Mylist1.add(10)

In this case, I would like only 2 values (Mylist.size) in mbc1.ChartData = ArrayAs Float()

and

Dim MyList1 as list
Mylist1.add(125)
Mylist1.add(10)
Mylist1.add(50)
Mylist1.add(200)

In this case, I would like only 4 values (Mylist.size) in mbc1.ChartData = ArrayAs Float()

Is it possible and how ?

Thanks
 

Yayou49

Active Member
Licensed User
Hi Mahares,

Sorry for the double thread.
I was not sure to be read in the Library thread.
I promise, I will not do that again ;)

Anyway, thanks for your answer !!
 

Paulsche

Well-Known Member
Licensed User
Hello Johan,

it is possible ti insert a horizontal line for minimum- maximum- and average values?
 

Mahares

Well Known Member
Licensed User
Here is how I do it for the average horizontal line:
B4X:
Dim Myarr() As Float = Array As Float(50.3,45.9,30.1, 23.1, 75.3)
Dim MyTot, MyAv As Float
'Calculate the average of the array
For i=0 To Myarr.Length -1   
    MyTot=MyTot+ Myarr(i)
Next
MyAv=(MyTot/Myarr.Length)
'Create a new array of the average
Dim MyArrayAverage(Myarr.Length) As Float
For i=0 To Myarr.Length -1
    MyArrayAverage(i) = MyAv
Next
'apply array of average to chart to plot a horizontal line
mlc1.Chart_1_Data = MyArrayAverage   'or Chart_2, Chart_3, Chart_4, Chart_5
For the min and max lines, you can see a method I wrote in my post #2 of the following link, that shows you how to calculate min and max of an array:
https://www.b4x.com/android/forum/threads/how-to-find-minimum-and-maximum-from-the-double-array.20123/#post-116377
If you have a problem, Johan will bail you out.
 

Paulsche

Well-Known Member
Licensed User
Here is how I do it for the average horizontal line:
B4X:
Dim Myarr() As Float = Array As Float(50.3,45.9,30.1, 23.1, 75.3)
Dim MyTot, MyAv As Float
'Calculate the average of the array
For i=0 To Myarr.Length -1  
    MyTot=MyTot+ Myarr(i)
Next
MyAv=(MyTot/Myarr.Length)
'Create a new array of the average
Dim MyArrayAverage(Myarr.Length) As Float
For i=0 To Myarr.Length -1
    MyArrayAverage(i) = MyAv
Next
'apply array of average to chart to plot a horizontal line
mlc1.Chart_1_Data = MyArrayAverage   'or Chart_2, Chart_3, Chart_4, Chart_5
For the min and max lines, you can see a method I wrote in my post #2 of the following link, that shows you how to calculate min and max of an array:
https://www.b4x.com/android/forum/threads/how-to-find-minimum-and-maximum-from-the-double-array.20123/#post-116377
If you have a problem, Johan will bail you out.
ok, thank you, that is a possibility, but I have the problem,
I already have three line-charts in my artwork and a maximum of five
possible are.
So if I do a minimally medium- and maximum line want, then I would need
six charts.

The way I see it, this is not feasible at combinedLineBarChart.
 

Johan Schoeman

Expert
Licensed User
ok, thank you, that is a possibility, but I have the problem,
I already have three line-charts in my artwork and a maximum of five
possible are.
So if I do a minimally medium- and maximum line want, then I would need
six charts.

The way I see it, this is not feasible at combinedLineBarChart.
It is limited to 5 line charts. If you want more than 5 then you should change all the code in the wrapper and recompile it into a new library.
 

Johan Schoeman

Expert
Licensed User
ok, thank you, that is a possibility, but I have the problem,
I already have three line-charts in my artwork and a maximum of five
possible are.
So if I do a minimally medium- and maximum line want, then I would need
six charts.

The way I see it, this is not feasible at combinedLineBarChart.
I will add some more line charts to the library in the next week or so and then post a new library for multi line charts so that you can draw at least your 6 lines.
 

Johan Schoeman

Expert
Licensed User
ok, thank you, that is a possibility, but I have the problem,
I already have three line-charts in my artwork and a maximum of five
possible are.
So if I do a minimally medium- and maximum line want, then I would need
six charts.

The way I see it, this is not feasible at combinedLineBarChart.
The attached library files should now make provision for 10 line charts in the MultiLineChart graph. I have only tested for line charts 1 to 6 - please let me know should something not be working as it should.
 

Attachments

Paulsche

Well-Known Member
Licensed User
Thanks, if 10 Line charts possible with combined Line Bar chart?
Otherwise I can insert the min-max mid-lines only when Multiline charts.
 

Johan Schoeman

Expert
Licensed User
Thanks, if 10 Line charts possible with combined Line Bar chart?
Otherwise I can insert the min-max mid-lines only when Multiline charts.
Yes, it is once the code in the wrapper has been modified. Will do it this week sometime (meaning before the end of Sunday ;))
 
Last edited:

Johan Schoeman

Expert
Licensed User
Thanks, if 10 Line charts possible with combined Line Bar chart?
Otherwise I can insert the min-max mid-lines only when Multiline charts.
Please try the attached library files for the MultiLineBarChart graph. I have allowed for 10 line charts. Please note that I have not tested it at all. Let me know if something seems to be out of "line". I have not added any additional features as what I have added to MultiLineCharts over a period of time - merely made provision for 10 line charts in the MultiLineBarChart. All other cosmetic features of MultiLineBarChart remain as is i.e in accordance with the last posting that I have done for MultiLineBarChart.
 

Attachments

Last edited:

Johan Schoeman

Expert
Licensed User
Can you add? Would be nice.
Can you add? Would be nice.
The Github project that I have wrapped does not at present provide for multi bar + multi line charts. I have mentioned it somewhere previously in this thread. The author of the Github project did mention in a forum that he is working on it. Once he makes it available I will wrap it and add it to the library.
 

beaker

Member
Licensed User
Hi Johan,
I'm using mpChart v1.01 with B4A 5.80 and I'm having a bit of an issue with right Y axis labels on a MultiLineChart. I originally posted the issue in the Android Questions forum a few days ago and user mc73 guided me here to post it as a possible bug report.

The issue appears or disappears depending on the left hand Y axis values. I've stripped out most of the code from my app which isn't relevent and attached the zipped up project as well as some screenshots showing the issue. The first screenshot looks as I'd expect but the second one looks as though the right hand Y axis values have been rounded to the nearest integer.

To explain the charts: There are five sets of data on each chart, 4 of them are tied to the left hand Y axis and the fifth (cyan dashed) is tied to the right hand Y axis. The only difference between the two sets of data is in the values behind the lines tied to the left hand Y axis, the data behind the right side Y axis is the same in both cases. You'll see that the right Y axis values shown are: 0.00, 0.60, 1.20, 1.80, 2.40, 3.00 in the first screenshot and 0, 1, 1, 2, 2, 3 in the second screenshot.

I'm leaving the Y axes limits to be automatically set.
Somehow the right hand Y axis label values are being influenced by the left hand Y axis values.

Chart1.png Chart2.png

Since my original post I've made some changes to see if I could narrow down the problem. I've added the following to see what affect it had:

chrtChart.YaxisLeftMinVal = 0
chrtChart.YaxisLeftMaxVal = 300

chrtChart.YaxisRightMinVal = 0
chrtChart.YaxisRightMaxVal = 3

The results are shown in the following screenshots (using the same underlying data as before):

Chart1 (fixed Y axes limits).png Chart2 (fixed Y axes limits).png

As you can see, the 1st image looks just fine. Obviously 4 of the lines are squashed right down the bottom but that's to be expected having set the left Y axis limits to the chosen values. The 2nd image is still showing the same (original) issue. So it looks as though the issue is related to the actual (left hand) graphed values and not the left Y axis limits. I've also noticed that the left Y axis labels in the 2nd image have been formatted with no decimals even though the axis limits haven't changed. What I'm guessing from this is that both sets of Y axis labels are being rounded to the nearest integer somehow.

Hopefully you'll get some time to take a look at this and that I've managed to narrow down where the problem might be.
Any help would be greatly appreciated.

I've attached the zipped project (modified since original post in other subforum). If you need me to do anything else just let me know.

Many thanks
Marcus
 

Attachments

Top