B4X Store

ELEVATEUI · B4A · XUI

UIBarChart

Compare values among categories; choose grouped bars for one series and the optional line for a second metric.

78 modules 1,780 APIs

Charts & visualizations

What it solves

Compare values among categories; choose grouped bars for one series and the optional line for a second metric.

Animated conceptual demonstration, not an exact Android control screenshot.

33 methods10 Designer1 events

When to use this module

In an analytics screen, choose this visualization when the user needs to compare the values represented by its axes or series.

Before integrating, examine its methods, events and Designer options.

B4A integration examples

Tutorials are based on existing project examples or audited APIs. Check each example’s prerequisites; B4A compilation is not claimed.

Chart implementation from documented B4A example
Existing documentation example charts-registry.json Not B4A-compiled

Review required libraries, Designer views and input data before compiling in B4A.

' Ejemplo autocontenido para la Activity principal de B4A.
' Habilitar las bibliotecas XUI y ElevateUI.
Sub Process_Globals
    Private xui As XUI
End Sub

Sub Globals
    Private Root As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Root = xui.CreatePanel("")
    Activity.AddView(Root, 0, 0, 100%x, 100%y)
    Root.Color = 0xFFF8FAFC
    Dim chart As UIBarChart
    chart.Initialize(Me, "Revenue")
    chart.AddToParent(Root, 12dip, 20dip, 100%x - 24dip, 260dip)
    chart.setData(L(Array As Object("Ene","Feb","Mar","Abr")), L(Array As Object(30,48,37,65)))
    chart.setTextTitle("Ventas mensuales")
    chart.setShowGrid(True)
    chart.setGradient(True)
    chart.setBarSeriesName("Ventas")
    chart.setLineSeries(L(Array As Object(24,33,45,51)), "Objetivo", 0xFF16A34A)
    chart.setShowLineValues(True)
End Sub

' Convierte un array de Object en una lista B4A.
' Necesario para las firmas que aceptan List.
Private Sub L(Values() As Object) As List
    Dim Result As List
    Result.Initialize
    Result.AddAll(Values)
    Return Result
End Sub

Private Sub Revenue_Click
    Log("Se pulsó el gráfico")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause(UserClosed As Boolean)
End Sub

Public methods reference

33 audited signatures

Public Sub Initialize (Callback As Object, EventName As String)

Prepare the instance before its other methods.

Callback As ObjectEventName As String
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)

Invoked automatically by the B4A Visual Designer; do not call manually.

Base As ObjectLbl As LabelProps As Map
Public Sub AddToParent(Parent As B4XView, Left As Int, Top As Int, Width As Int, Height As Int)

Add this view to a parent container using the supplied bounds and options.

Parent As B4XViewLeft As IntTop As IntWidth As IntHeight As Int
Public Sub setData(PointsX As List, Values As List)

Update data at runtime when this setting changes.

PointsX As ListValues As List
Public Sub setLineSeries(Values As List, SeriesName As String, Color As Int)

Update line series at runtime when this setting changes.

Original catalog note: Adds a line series over the bars. Values must match the X labels.

Values As ListSeriesName As StringColor As Int
Public Sub setBarSeriesName(SeriesName As String)

Update bar series name at runtime when this setting changes.

SeriesName As String
Public Sub setShowLineValues(Show As Boolean)

Update show line values at runtime when this setting changes.

Show As Boolean
Public Sub clearLineSeries

Use clearLineSeries for its named operation; follow its exact signature.

Public Sub setTitleFont(Font As B4XFont)

Update title font at runtime when this setting changes.

Font As B4XFont
Public Sub setTitleColor(Color As Int)

Update title color at runtime when this setting changes.

Color As Int
Public Sub setXAxisTextColor(Color As Int)

Update xaxis text color at runtime when this setting changes.

Color As Int
Public Sub setTextTitle(Title As String)

Update text title at runtime when this setting changes.

Title As String
Public Sub setColor(color As Int)

Update color at runtime when this setting changes.

color As Int
Public Sub setColors(Colors1 As List)

Update colors at runtime when this setting changes.

Original catalog note: Uses one color per category; setColor restores the single-color mode.

Colors1 As List
Public Sub setShowValues(Show As Boolean)

Update show values at runtime when this setting changes.

Show As Boolean
Public Sub setSuffix(Suffix As String)

Update suffix at runtime when this setting changes.

Suffix As String
Public Sub setGradient(Use As Boolean)

Update gradient at runtime when this setting changes.

Use As Boolean
Public Sub setBarWidth(Width As Float)

Update bar width at runtime when this setting changes.

Original catalog note: Rounds the free/top end of each column when enabled. Space between categories in pixels. Pass 5dip, for example; -1 restores automatic spacing. Spacing changes positions only; bar width is independent. Column width in current pixels. Pass 28dip, for example.

Width As Float
Public Sub getBarWidth As Float

Read the current bar width value for validation or UI synchronization.

Returns: Float

Public Sub setBarSpacing(Spacing As Float)

Update bar spacing at runtime when this setting changes.

Spacing As Float
Public Sub getBarSpacing As Float

Read the current bar spacing value for validation or UI synchronization.

Returns: Float

Public Sub setRoundedBars(Enabled As Boolean)

Update rounded bars at runtime when this setting changes.

Enabled As Boolean
Public Sub SaveAsPNG(Dir As String, FileName As String) As Boolean

Use SaveAsPNG for its named operation; follow its exact signature.

Dir As StringFileName As String

Returns: Boolean

Public Sub setShowAxes(Show As Boolean)

Update show axes at runtime when this setting changes.

Original catalog note: Shows or hides X and Y axis lines without hiding category labels.

Show As Boolean
Public Sub getShowAxes As Boolean

Read the current show axes value for validation or UI synchronization.

Returns: Boolean

Public Sub setShowYAxisValues(Show As Boolean)

Update show yaxis values at runtime when this setting changes.

Original catalog note: Numeric Y-axis scale visibility is independent of individual data values.

Show As Boolean
Public Sub getShowYAxisValues As Boolean

Read the current show yaxis values value for validation or UI synchronization.

Returns: Boolean

Public Sub setShowGrid(Show As Boolean)

Update show grid at runtime when this setting changes.

Show As Boolean
Public Sub getShowGrid As Boolean

Read the current show grid value for validation or UI synchronization.

Returns: Boolean

Public Sub setGridColor(Color As Int)

Update grid color at runtime when this setting changes.

Color As Int
Public Sub getGridColor As Int

Read the current grid color value for validation or UI synchronization.

Returns: Int

Public Sub setGridInterval(Interval As Float)

Update grid interval at runtime when this setting changes.

Interval As Float
Public Sub getGridInterval As Float

Read the current grid interval value for validation or UI synchronization.

Returns: Float

Designer · 10

#DesignerProperty: Key: BarColor, DisplayName: Bar Color, FieldType: Color, DefaultValue: #FF8A2BE2, Description: Color of the bars (purple as in the image)#DesignerProperty: Key: ShowMarker, DisplayName: Show Point Values, FieldType: Boolean, DefaultValue: True, Description: Shows the values above each bar#DesignerProperty: Key: MarkerText, DisplayName: Title Text, FieldType: String, DefaultValue: API Calls#DesignerProperty: Key: Animate, DisplayName: Animate, FieldType: Boolean, DefaultValue: True#DesignerProperty: Key: Duration, DisplayName: Animation Duration, FieldType: Int, DefaultValue: 1000, Description: Duration in milliseconds#DesignerProperty: Key: ValueSuffix, DisplayName: Value Suffix, FieldType: String, DefaultValue: , Description: Suffix for bar values (e.g., %, $, etc.)#DesignerProperty: Key: UseGradient, DisplayName: Use Gradient Fill, FieldType: Boolean, DefaultValue: False, Description: Use a gradient fill for the bars#DesignerProperty: Key: ShowGrid, DisplayName: Show Grid, FieldType: Boolean, DefaultValue: False, Description: Shows or hides the horizontal grid lines#DesignerProperty: Key: GridColor, DisplayName: Grid Color, FieldType: Color, DefaultValue: 0xFF64748B, Description: Color of the horizontal grid lines#DesignerProperty: Key: GridInterval, DisplayName: Grid Interval, FieldType: Float, DefaultValue: 0, Description: Step interval value for grid lines (e.g. 100, 1000). Set to 0 for automatic division.

Public events and how to implement them · 1

Initialize with Me and the event prefix Demo, then add the following handler to your B4A module. Names and arguments come from the library declaration.

Click

Raised when the user taps the control; use it to trigger a real action.

B4A handler signature with Demo prefix

Private Sub Demo_Click()
    Log("Click")
End Sub

For code-created controls use Initialize(Me, "Demo") when that signature exists; for Designer controls set the event name there. Replace Demo with the actual prefix.

Public fields, constants and types

Public mBase As B4XView
Source: ElevateUI public API catalog; tutorials cross-checked against ElevateUI(6).b4xlib. Visualizations are illustrative; sample code requires B4A compilation.