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

BarryW

Active Member
Licensed User
Longtime User
I have error now in ur library

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

 

Johan Schoeman

Expert
Licensed User
Longtime 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)



 

Attachments

  • mpChartLib.zip
    350.8 KB · Views: 306
  • B4AMultiLineChartV5.zip
    378.4 KB · Views: 356

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
Longtime User
Hello Johan,

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

Mahares

Expert
Licensed User
Longtime 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/t...imum-from-the-double-array.20123/#post-116377
If you have a problem, Johan will bail you out.
 

Paulsche

Well-Known Member
Licensed User
Longtime 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.
 

Johan Schoeman

Expert
Licensed User
Longtime User
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
Longtime User
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
Longtime User
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

  • mpChartLibFiles29Feb.zip
    352.5 KB · Views: 232

Paulsche

Well-Known Member
Licensed User
Longtime 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
Longtime 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
Longtime 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

  • mpChartLibLibFiles2March.zip
    354 KB · Views: 227
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime 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.



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):



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

  • MLC Right Y Axis Labels Issue.zip
    35.9 KB · Views: 249
Cookies are required to use this site. You must accept them to continue using the site. Learn more…