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

Johan Schoeman

Expert
Licensed User
Longtime User
Library V1.17 in post #1 of this thread. Use it as follows to display or hide the MarkerView

B4X:
mlc1.DisplayMarker = False    'or mlc1.DisplayMarker = True

Have set the default value in the library to FALSE

Have only added it to single and multi line charts for now.
 

incendio

Well-Known Member
Licensed User
Longtime User
Hi, thanks for this library.

I downloaded these files from post #1
1. mp4ChartLibraryfiles.zip
2. mp4ChartLibv1.17.zip
3. b4aMPChart.zip

There is double file in no 1 & 2, so I choose newer one.
When running example, got this error :
Unknown Member setTheLegendPosition

I was also tried sample from post #6 & #9, Barchart, got error when running:
An error has occured in sub main_activity_create, android.content.res
Resources$NotFoundException:
Resource ID #0x0


Am I missing something?
Note : B4A v9.5
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
See post #12 for the ResourcesNotFoundException

Note that some methods have changed name over the years - find the correct method(s) in the drop down method list when for ex typing mlc1.
 

incendio

Well-Known Member
Licensed User
Longtime User
See post #12 for the ResourcesNotFoundException

Note that some methods have changed name over the years - find the correct method(s) in the drop down method list when for ex typing mlc1.

Example from post #6 & #9 now run OK, thanks, but example from post #1 still error.

In example post #1 I changed
setTheLegendPosition -> TheLegendPosition = "RIGHT_OF_CHART"

and got error :
ClassNotFoundExection : JHS.MPChart.pieViewWrapper
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Example from post #6 & #9 now run OK, thanks, but example from post #1 still error.

In example post #1 I changed
setTheLegendPosition -> TheLegendPosition = "RIGHT_OF_CHART"

and got error :
ClassNotFoundExection : JHS.MPChart.pieViewWrapper
Try with the attached project with library V1.17 that is posted in post #1 of this thread.
Extract ProjectRes.zip and copy the folder and its contents to be on the same folder level of the B4A project's /Object and /Files folder (just making it a bit easier so that the files don't get deleted if their properties are not set to READ ONLY when they are in the /Objects/res/drawable and Objects/res/layout folders and you compile the B4A project).

Long click on the pie chart to get a bitmap that will be displayed in the Imageview on the left. Handle the returned bitmap in your B4A code.


 

Attachments

  • b4aMPPieChart.zip
    8.6 KB · Views: 414
  • ProjectRes.zip
    24.4 KB · Views: 381

incendio

Well-Known Member
Licensed User
Longtime User
Thanks, now work as a charm.

Perhaps, the example from post # could be updated with this.
 

seyed_27

Member
How to design the following chart
So that there is a gap between the two parts of the lines
 

Attachments

  • 123121068-510x293.jpg
    42.1 KB · Views: 334

Alex_Puz

Member
Licensed User
Longtime User
Thank you for library Ver. 1.17.
Can you add some feature to radar chart which can feel area between two data with some color
something like this mrc1.setRadarFeel(2,3,Color.Blue)? and draw.feel false or true as mrc1.draw.feel(1)=True (False)
also something like mrc1.setRadarRing(radius,thickness)
 
Last edited:

seyed_27

Member
How to draw several horizontal lines with different colors in a specific position
Like this example
Horizontal point 69
Horizontal point 58
Horizontal point 49
How to design the following chart
So that there is a gap between the two parts of the lines
 

Fritzi

Member

Hi, thanks for your great work !
I am a newbie and I saw, that the pie chart can be rotated with a finger.
Is it possible to rotate it by code ?

Thank you very much
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi, thanks for your great work !
I am a newbie and I saw, that the pie chart can be rotated with a finger.
Is it possible to rotate it by code ?

Thank you very much
Download lib files V1.18 from post #1 in this thread. Sample B4A project attached. Make sure you also download attached ProjectRes.zip, extract it, and copy the folders (with their contents) to be on the same folder level as the /Files folder of the B4A project.

B4X:
#Region  Project Attributes
    #ApplicationLabel: MPPieChart
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\ProjectRes

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
    Dim t As Timer

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private mpc1 As PieChart
   
    Private iv1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
   
    t.Initialize("t", 1000)
   
    mpc1.UsePercentValues = True
   
    mpc1.DrawHoleEnabled = True
    mpc1.HoleColorTransparent = True

    mpc1.TransparentCircleColor = Colors.White
    mpc1.TransparentCircleAlpha = 110

    mpc1.HoleRadius = 58.0
    mpc1.TransparentCircleRadius = 61.0

    mpc1.DrawCenterText = True

    mpc1.CenterText = "Wrapped by Johan"
    mpc1.CenterTextColor = Colors.White
    mpc1.CenterTextRadiusPercent = 100.0
    mpc1.CenterTextSize = 12.0

    mpc1.DrawSliceText = True
    mpc1.HoleColor = Colors.Black
    mpc1.TransparentCircleColor = Colors.Transparent

    mpc1.RotationEnabled = True


'    RIGHT_OF_CHART, RIGHT_OF_CHART_CENTER, RIGHT_OF_CHART_INSIDE,
'    LEFT_OF_CHART, LEFT_OF_CHART_CENTER, LEFT_OF_CHART_INSIDE,
'    BELOW_CHART_LEFT, BELOW_CHART_RIGHT, BELOW_CHART_CENTER,
'    PIECHART_CENTER
'     Use any one of the two methods below
'     mpc1.TheLegendPosition = "RIGHT_OF_CHART"
     mpc1.TheLegendPosition = mpc1.LP_RIGHT_OF_CHART
   

   
    mpc1.TheLegendColor = Colors.yellow
    mpc1.TheLegendTextSize = 12.0
    mpc1.LegendTitle = "MONTHS"

    mpc1.ChartDescription = "TITLE : Some Arbitrary Data"
    mpc1.ChartDescriptionColor = Colors.ARGB(200,0,255,255)
    mpc1.ChartDescriptionTextSize = 14

    mpc1.ValueTextColor = Colors.Black
    mpc1.ValueTextSize = 12.0

    mpc1.PieColors = Array As Int(Colors.Blue, Colors.Yellow, Colors.Green, Colors.Red, Colors.Magenta, Colors.Cyan)
    mpc1.LegendText = Array As String("Jan", "Feb", "Mar", "Apr", "May", "Jun")
    mpc1.ChartData = Array As Float(128.0, 16.0, 46.0, 40.0, 30.0, 40.0)    'values - it will be converted to %
   
    mpc1.PieData = 6    
   
       

End Sub

Sub Activity_Resume

    t.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub mpc1_value_selected(index As Int, value As Float)
   
    Log("index = " & index)
    Log("value = " & value)
   
   
End Sub

Sub mpc1_long_pressed
   
    Log("Long Pressed")
    Dim bm As Bitmap = mpc1.ChartBitmap
    iv1.Bitmap = bm
   
End Sub

Sub t_tick
   
    mpc1.spin(500, 0, 360)

   
End Sub
 

Attachments

  • b4aMPPieChart.zip
    8.7 KB · Views: 329
  • ProjectRes.zip
    24.4 KB · Views: 320
Last edited:

Fritzi

Member

Hi, that looks sooo cooool
Now it looks like a wheel of fortune, when rotating. Amazing animation.
Thank you very much
 

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Great job Dude!!
 

Fritzi

Member

Hi Johan,
just another idea:
It would be additionally even more cooler, when a user spins the piechart and it returns values per code -/- range of the double variable for example.
x=mpc1.GetSpin(Value As Double)
 

Inman

Well-Known Member
Licensed User
Longtime User
Thanks for the library. One issue I noticed is that if the legend position is set to bottom centre, some text characters get cut off. Like if legend has a string called "Pending", the bottom portion of "g" gets cut off. Could you please fix this?

Also another request that is not urgent is to enable Typeface support for ValueText, LegendText etc... That way we can set the text style to bold if necessary.
 

MomoWen

Member
Licensed User

StackedBarChart Can you add more color layers
 

Johan Schoeman

Expert
Licensed User
Longtime User
Have added V1.20 to post #1 of this thread. It allows for highlighting up to 10 points simultaneously in the single line chart (requested by @Cenny). Have also added a method to clear all highlights.



Sample code in sub t_tick of the attached project:
B4X:
Sub t_tick
    cntr = cntr + 1
    If cntr = 10 Then cntr = 0
    mlc4.clearValues
    Dim myfloat() As Float = Array As Float(31.534, 63.419, -17.512, 27.334, 83.659, -54.103, 60.512, -15.773, -19.541, -45.845, 68.313, -5.708)
    mlc4.ChartData = myfloat
    mlc4.LineData = 12
    
    If cntr < 5 Then
        Dim myhighlight() As Int = Array As Int(0, 4, 7, 8)      <-------- prepare array of x value indexes to highlight simultaneously
        mlc4.MultipleHighlight = myhighlight                      <--------- pass the array of indexes to highlight to the library
    Else
        mlc4.clearHighlight           <---------clear the highlights programmatically
    End If   
        
End Sub
 

Attachments

  • MPLineChart27122021.zip
    291.2 KB · Views: 237

f0raster0

Well-Known Member
Licensed User
Longtime User
hi team,

Does any one know if this Line Chart work only for a fixed number of x-axis values? Link

B4X:
mlc1.Chart_1_Data = Array As Float(1100.0, 550.0, 550.0, 300.0, 600.5, 445.0, 849.7, 250.4, 380.2, 345.0, 453.5, 783.7)
mlc1.XaxisLables = Array As String("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
mlc1.setLineData(1,12)

We are seeking a solution to read data and display it on the graph, beginning from 1 without a fixed endpoint. Additionally, we want the option to display only a specified number of data points, such as 20, with the ability to scroll through the data.

Thanks in advance
 

Johan Schoeman

Expert
Licensed User
Longtime User
Only a fixed number of data points.

You can try this one

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