B4A Library MPAndroidCharts - Various type of graphs / charts (most recent library files in post #362)

Discussion in 'Additional libraries, classes and official updates' started by Johan Schoeman, Sep 5, 2015.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Why don't you use the secondary y-axis....
     
  2. peacemaker

    peacemaker Well-Known Member Licensed User

    I need to detailed compare 7 lines that each of various values range. Pressure, humidity, temperature....
    At the same scale, but absolute values are important just after comparision.
    So, values for drawing are of various ranges, but should ein the same scale, and absolute values should also be readable, on marker.
     
    Last edited: Aug 16, 2017
  3. Ricardo Escalante

    Ricardo Escalante Member Licensed User

    Hi, how are you? Could you help me with the next problem, please?
    Running the application throws me the next dump, trying to generate a bar graph and almost the same with the graph pay

    Library ver. installed 1.06
    B4A ver. 7.3 Beta#1

    main_cargadatosbarra (B4A line: 201)
    barra.LegendShapeSize = 7.0 'this line of
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.invalidate()' on a null object reference
    at mpandroidchartwrapper.barChartWrapper.setLegendShapeSize(barChartWrapper.java:422)
    at com.easypoll.main._cargadatosbarra(main.java:515)
    at com.easypoll.main._lstoficinas_itemclick(main.java:874)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA$1.run(BA.java:325)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6123)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.invalidate()' on a null object reference

    I really appreciate your time and response.
     
    Last edited: Aug 31, 2017
  4. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Ricardo - is it your own project that gives you the error or my demo project?

    See what the attached lib files does. I have no problem with the barcode part of the library when running my demo project.

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

    #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.

    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 mbc1 As BarChart
        
    Dim prevval As Float = 0.0
      
        
    Private Label1 As Label
    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")
      
        Label1.Text = 
    "Value = "
      
    '    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,

    '   LINE, CIRCLE, SQUARE
        mbc1.LegendShapeSize = 7.0        'this line of code needs to be before mbc1.setTheLegendPositionAndForm("BELOW_CHART_CENTER", "CIRCLE")
        mbc1.setTheLegendPositionAndForm("BELOW_CHART_CENTER""CIRCLE")    'pass strings from the above comments
      
        mbc1.TheLegendColor = 
    Colors.yellow
        mbc1.TheLegendTextSize = 
    20.0
        mbc1.LegendTitle = 
    "Months"

        mbc1.ChartDescription = 
    "TITLE : Some Arbitrary Data"
        mbc1.ChartDescriptionColor = 
    Colors.Black
        mbc1.ChartDescriptionTextSize = 
    15
    '    mbc1.setDescriptionPosition(mbc1.left + 25%x ,mbc1.top + 3%y)
      
        mbc1.ValueTextColor = 
    Colors.Black
        mbc1.ValueTextSize = 
    9.0
      


        
    'the following 3 arrays must have the same number of entries/elements
        mbc1.BarColors = Array As Int(Colors.Blue, Colors.Yellow, Colors.Green, Colors.Red, Colors.Magenta, Colors.Cyan, Colors.Blue, Colors.Yellow, Colors.Green, Colors.Red, Colors.Magenta, Colors.Cyan, _
                                      
    Colors.Blue, Colors.Yellow, Colors.Green, Colors.Red, Colors.Magenta, Colors.Cyan, Colors.Blue, Colors.Yellow, Colors.Green, Colors.Red, Colors.Magenta, Colors.Cyan)
        mbc1.LegendText = 
    Array As String("1""2""3""4""5""6""7""8""9""10""11""12""13""14""15""16""17""18""19""20","21""22""23""24")
        mbc1.ChartData = 
    Array As Float(52.058.063.070.048.038.025.053.066.046.067.075.052.058.063.070.048.038.025.053.066.046.067.075.0)    'values - it will be converted to %

        mbc1.DoubleTapToZoomEnabled = 
    True
        mbc1.DrawBarShadow = 
    False
        mbc1.GridBackgroundColor = 
    Colors.white
        mbc1.DrawBorders = 
    True
        mbc1.DrawGridBackground = 
    True
        mbc1.DrawHighlightArrow = 
    True
        mbc1.DrawValueAboveBar = 
    True
        mbc1.PinchZoom = 
    True
        mbc1.ScaleEnabled = 
    True
        mbc1.BorderColor = 
    Colors.Yellow
        mbc1.BorderWidth = 
    3.0

    '   TOP, BOTTOM, BOTH_SIDED, TOP_INSIDE, BOTTOM_INSIDE
        mbc1.XaxisLabelPosition = "BOTTOM"
        mbc1.XaxisTextSize = 
    15.0
        mbc1.XaxisTextColor = 
    Colors.Magenta
      
        mbc1.DrawYaxisGridLines = 
    True
        mbc1.YaxisTextColor = 
    Colors.Green
        mbc1.YaxisTextSize = 
    15.0
        mbc1.ShowYaxisLeftLabels = 
    True
        mbc1.ShowYaxisRightLabels = 
    False
        mbc1.MarkerToUse = 
    1
      
        mbc1.YAxisMinValue = 
    0                           'ADDED 29 October 2015
        mbc1.YAxisMaxValue = 100                          'ADDED 29 October 2015
      
        mbc1.YAnimate = 
    True
        mbc1.ChartAnimationTime = 
    2000

      
        mbc1.BarData = 
    24   'this number must be the same as the number of elements in the above arrays

    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub mbc1_bar_value(val As Float, index As Int)
      
        
    If prevval <> val Then
            
    Log("Current Value = " & val & ": Index = " & index)
          Label1.Text = 
    "Value = " & val & ": Index = " & index
          prevval = val
        
    End If
      
    End Sub
    Take note of the comment in the code:
    Code:
    '   LINE, CIRCLE, SQUARE
        mbc1.LegendShapeSize = 7.0        'this line of code needs to be before mbc1.setTheLegendPositionAndForm("BELOW_CHART_CENTER", "CIRCLE")
     

    Attached Files:

    Last edited: Aug 31, 2017
  5. Ricardo Escalante

    Ricardo Escalante Member Licensed User

    Thanks so much for the response!
    Let me try to explain me (sorry for my english)

    Error, is it in my own project, i used your code sample just to load some data, but if i upgrade the library to 1.06 or 1.07(post #126)gives me the error.
    Both pie and barrs charts
    At pie chart,

    pay.PieColors = Array As Int(Colors.Green, Colors.Yellow, Colors.Red)
    pay.LegendText = Array As String("Bien", "Regular", "Mal")
    pay.ChartData = Array As Float(60.0, 26.0, 46.0) 'values - it will be converted to %
    pay.PieData = 3

    throws error in line: pay.PieData = 3

    Rigth now i works with 1.0 Post#3 and works fine.

    Although I would like to work with 1.06

    Again, thank you very much
     
  6. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Try the lib files in post #304 above - it is version 1.08
     
  7. Ricardo Escalante

    Ricardo Escalante Member Licensed User

    the same error:

    main_cargapay (B4A line: 221)
    pay.PieData = 3
    android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2094)
    at android.content.res.Resources.getLayout(Resources.java:1111)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:424)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
    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:30)
    at mpandroidchartwrapper.pieChartWrapper.setPieData(pieChartWrapper.java:219)
    at com.easypoll.main._cargapay(main.java:690)
    at com.easypoll.main._lstoficinas_itemclick(main.java:848)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA$1.run(BA.java:325)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6123)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)


    As well as downloading the library and the xml copy them in C: \ Program Files (x86) \ Anywhere Software \ Basic4android \ Libraries.
    Maybe something is missing or doing wrong

    Thanks!!
     

    Attached Files:

  8. Johan Schoeman

    Johan Schoeman Expert Licensed User

    You are missing the resource files in the /Objects/res folder - I guess. They need to be set to READ ONLY BEFORE you run the B4A project else the files in the /Object/res folder will get deleted when you compile the B4A project
     
    Last edited: Aug 31, 2017
  9. Ricardo Escalante

    Ricardo Escalante Member Licensed User

    This is the project.
     

    Attached Files:

  10. Johan Schoeman

    Johan Schoeman Expert Licensed User

    What version of B4A are you using. Your layout file is missing (.bal) from the project above
     
  11. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Solved using team viewer......
     
    Last edited: Aug 31, 2017
    DonManfred likes this.
  12. Ricardo Escalante

    Ricardo Escalante Member Licensed User

    Thank you very much the project is already working.
    I think I have ventured into this environment without having the necessary knowledge, I am learning on the go.

    I can not thank you enough.
     
    aidymp and Johan Schoeman like this.
  13. matek

    matek Member Licensed User

    Hello
    I have a question about the lib
    What could be the cause of such a chart?
     

    Attached Files:

  14. beaker

    beaker Member Licensed User

    I think this is probably due to the 'CubicIntensity' value for the line. Try a smaller value and see whether that improves things.
     
  15. matek

    matek Member Licensed User

    thank you very much, it helped
     
  16. wimpie3

    wimpie3 Well-Known Member Licensed User

    I'm using the CombinedChart and it seems that:

    1. the YaxisLeftMinVal and/or YaxisrightMinVal are not used if the value is > 0. I'm using "100" as the value, but the bar charts seem to start always at minimal position 0...

    2. individual bars cannot have a different color?

    3. only one line chart can be added to a CombinedChart?

    Furthermore, in general: null values are not supported? This means that EVERY X-point needs a value in the line graph? :-(
     
    Last edited: Sep 14, 2017
  17. Johan Schoeman

    Johan Schoeman Expert Licensed User

    @wimpie3, I have made so many changes to the original code of the MPAndroidChart project (based on request) that it will be no simple task to add additional features to it based on recent updates of the original code. I have added features to the original code that was not there in the first place - so it is just not a case of plugging in a revised class. Most of the original classes have been modified extensively. If you want to do the changes/amendments I am more than happy to post the library code as it is at present and you can then add the changes to it. Would you like me to post the Java code?
     
  18. matek

    matek Member Licensed User

    Hello
    I have a question
    Is it possible to display values X and Y in the position as indicated in the attachment
     

    Attached Files:

    • 1.png
      1.png
      File size:
      52.6 KB
      Views:
      297
  19. Johan Schoeman

    Johan Schoeman Expert Licensed User

    The attached project takes care of two of the issues that you raised - assigning different colors to the bars and setting the Min/Max values being displayed on the Y-Axis (left and right).

    It brings its own complexity to the party when changing the colors of the bars (as far as the legend is concerned). So what color do you want to be displayed as the bar color legend?

    Your other request - the original Github code that I have wrapped does not support more than one line/bar per combined line/bar chart. If you want me to look into this then let me know and I will let you know the cost of changing the code.

    This part of the mpAndroidChart project will expire on 29 September 2017.

    5.png
     

    Attached Files:

    Last edited: Sep 17, 2017
  20. kevinl

    kevinl New Member Licensed User

    Really a great library Johan, thanks!

    One question I have is the following:
    How can I format the numbers on for example the Y-axis (specifically set the number of decimals to a fixed amount)? I know this is possible in the originally library but haven't found this option here yet.

    Best regards,
    Kevin
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice