B4A Library desCharts - Bar Charts, Line Charts, Stacked Bar Charts, Stacked Line Charts(New update in post #17)

I have started wrapping this Github project. The library files are in the /files folder of the attached B4A project. Copy them to your additional library folder. Take note that the sequence of some code in the B4A project is important (see comments in the attached B4A project). You will also need android-support-v4.jar. You can download it from here. I have at present allowed for 3 series of data to be added but will change the code to accommodate more data series should anyone require more than 3. Will post the java source code once I have added the other charting options.

Enjoy....:)

2.png


Some sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: desBarChart
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
    #AdditionalJar: android-support-v4
#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 dbc1 As BarChartView
   
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")
    Dim serie As Int = 0

    'SET THE X-AXIS LABELS
    Dim lbls() As String = Array As String("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")    'prepare the x-axis labels
    dbc1.XaxisLabels = lbls
   
    'TAKE NOTE - THE ORDER OF EACH OF THE 3 FOLLOWING LINES OF CODE ARE IMPORTANT AND IT NEEDS TO BE BELOW THE ABOVE 2 LINES OF CODE THAT SETS THE x-axis LABELS       
   
    'SET THE DATA OF SERIES 1 - keep the order of the next 3 lines of code
    serie = 0
    Dim serie1data() As Float = Array As Float(25.0, 35.0, 48.3, 99.7, 45.2, -77.4, 125.3)      'series 1's data
    dbc1.Series1_Values = serie1data                                                           'set the data of series 1   
    dbc1.setLineStyle_3(serie, Colors.Transparent, Colors.Green, 0.0, False)                         'set style of series 1 - the outer color of the bars, the fill color of the bars, and using dip values or not

    'SET THE DATA OF SERIES 2 - keep the order of the next 3 lines of code
    serie = 1
    Dim serie2data() As Float = Array As Float(44.7, 94.3, 122.1, -45.5, 67.9, 0.0, 83.6)       'series 2's data
    dbc1.Series1_Values = serie2data                                                           'set the data of series 2
    dbc1.setLineStyle_3(serie, Colors.Transparent, Colors.Red, 0.0, False)                        'set style of series 2 - the outer color of the bars, the fill color of the bars, and using dip values or not
    'SET THE DATA OF SERIES 3 - keep the order of the next 3 lines of code
    serie = 2
    Dim serie3data() As Float = Array As Float(15.5, -42.1, 0.0, 98.6, 39.4, 0.0, 57.2)      'series 3's data
    dbc1.Series1_Values = serie3data                                                        'set the data of series 3
    dbc1.setLineStyle_3(serie, Colors.Transparent, Colors.Yellow, 0.0, False)                     'set style of series 3 - the outer color of the bars, the fill color of the bars, and using dip values or not
 
    'SET THE DATA OF SERIES 3 - keep the order of the next 3 lines of code
    serie = 3
    Dim serie3data() As Float = Array As Float(15.5, -42.1, 0.0, 98.6, 39.4, 0.0, 57.2)      'series 3's data
    dbc1.Series1_Values = serie3data                                                        'set the data of series 3
    dbc1.setLineStyle_3(serie, Colors.Transparent, Colors.Blue, 0.0, False)                     'set style of series 3 - the outer color of the bars, the fill color of the bars, and using dip values or not





    'Set the common chart parameters
    dbc1.BackgroundColor = Colors.ARGB(100, 0, 0, 255)              'set the background color
    dbc1.setGridColor(Colors.White, Colors.Red, Colors.Magenta)     'set the border color, grid color, and horixzontal axis color
    dbc1.setGridVis(True, True, True)                               'set the visibility of the border, grid, and centre horizonla axis
    dbc1.setGridWidth(2.0, 2.0, 2.0)                                'set the  width of the border, grid, and centre horizonla axis          
    dbc1.setTextStyle(Colors.White, 15.0)                           'set the color and size of the x-axis and y-axis text
    dbc1.GridAA = True                                              '....mmmmmmm....
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Attachments

  • b4aDesCharts.zip
    40.6 KB · Views: 391
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Top