B4X Store

ELEVATEUI · B4A · XUI

UIDonutChart

Display proportional parts of a whole with room for a center label.

78 modules 1,780 APIs

Charts & visualizations

What it solves

Display proportional parts of a whole with room for a center label.

Animated conceptual demonstration, not an exact Android control screenshot.

21 methods10 Designer1 events

When to use this module

Show completed versus remaining work in a compact ring, leaving its center for the total percentage.

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.

Interactive completion ring with an ElevateUI action button
Reviewed integration tutorial Adapted from UICharts(1).zip and ElevateUI(6) UIDonutChart public API Not B4A-compiled

B4A Activity, XUI and ElevateUI libraries. Uses an in-memory completed/remaining proportion; replace it with your actual task progress.

' UIDonutChart + UIButton: complete another task and update chart
Sub Process_Globals
End Sub

Sub Globals
    Private completion As UIDonutChart
    Private advance As UIButton
    Private percentComplete As Int
    Private xui As XUI
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.Color = 0xFFF2F5FC
    percentComplete = 60

    completion.Initialize(Me, "completion")
    completion.AddToParent(Activity, 12dip, 12dip, _
        Activity.Width - 24dip, 250dip)
    completion.TitleText = "Project completion"
    completion.IsHalfDonut = False
    completion.GapAngle = 5
    completion.InnerRadiusFactor = 0.62
    DrawCompletion

    advance.Initialize(Me, "advance")
    advance.AddToParent(Activity, 16dip, 278dip, _
        Activity.Width - 32dip, 46dip, 1, 15, "Complete another 10%", _
        Colors.White, 0xFF35B998, 0xFF3478C8, "LEFT_RIGHT", 10dip)
End Sub

Private Sub DrawCompletion
    completion.setIconCenter(percentComplete & "%", _
        0xFF243653, xui.CreateDefaultFont(22), 22)
    completion.SetData(Array As Object(percentComplete, 100 - percentComplete), _
        Array As Object("Complete", "Remaining"), _
        Array As Object(0xFF8B5CF6, 0xFFE2E8F0))
End Sub

Private Sub advance_Click
    percentComplete = Min(100, percentComplete + 10)
    DrawCompletion
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause(UserClosed As Boolean)
End Sub
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 UIDonutChart
    chart.Initialize(Me, "Budget")
    chart.AddToParent(Root, 12dip, 20dip, 100%x - 24dip, 260dip)
    chart.setTitleText("Distribución del presupuesto")
    chart.setIsHalfDonut(False)
    chart.setGapAngle(5)
    chart.setInnerRadiusFactor(0.62)
    chart.SetData( _
        L(Array As Object(45,30,25)), _
        L(Array As Object("Operación","I+D","Marketing")), _
        L(Array As Object(0xFF8B5CF6,0xFF06B6D4,0xFF10B981)))
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 Budget_MouseClicked
    Log("Se pulsó el anillo")
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause(UserClosed As Boolean)
End Sub

Public methods reference

21 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 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(listvalues As List, listlabels As List, listcolors As List)

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

listvalues As Listlistlabels As Listlistcolors As List
Public Sub setTitleTextFont(Font As B4XFont)

Update title text font at runtime when this setting changes.

Font As B4XFont
Public Sub setTitleTextSize(Size As Float)

Update title text size at runtime when this setting changes.

Size As Float
Public Sub setTitleText(Title As String)

Update title text at runtime when this setting changes.

Title As String
Public Sub setTitleTextColor(Color1 As Int)

Update title text color at runtime when this setting changes.

Color1 As Int
Public Sub setLegendTextColor(Color1 As Int)

Update legend text color at runtime when this setting changes.

Color1 As Int
Public Sub setUseGradients(Value As Boolean)

Update use gradients at runtime when this setting changes.

Value As Boolean
Public Sub setPercentageSuffix(Suffix As String)

Update percentage suffix at runtime when this setting changes.

Suffix As String
Public Sub setIconCenter(Text As String, Color1 As Int , font As B4XFont, size As Float)

Update icon center at runtime when this setting changes.

Text As StringColor1 As Intfont As B4XFontsize As Float
Public Sub setSubTextCenter(Text As String, Color1 As Int , font As B4XFont)

Update sub text center at runtime when this setting changes.

Text As StringColor1 As Intfont As B4XFont
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 setIsHalfDonut(Value As Boolean)

Update is half donut at runtime when this setting changes.

Original catalog note: Descripción: Obtiene o establece si el gráfico se mostrará como media dona (180 grados).

Value As Boolean
Public Sub getIsHalfDonut As Boolean

Read the current is half donut value for validation or UI synchronization.

Returns: Boolean

Public Sub setGapAngle(Angle As Int)

Update gap angle at runtime when this setting changes.

Original catalog note: Descripción: Obtiene o establece el ángulo de separación en grados entre cada sección.

Angle As Int
Public Sub getGapAngle As Int

Read the current gap angle value for validation or UI synchronization.

Returns: Int

Public Sub setInnerRadiusFactor(Factor As Float)

Update inner radius factor at runtime when this setting changes.

Original catalog note: Descripción: Obtiene o establece el factor del radio interno (rango de 0 a 1).

Factor As Float
Public Sub getInnerRadiusFactor As Float

Read the current inner radius factor value for validation or UI synchronization.

Returns: Float

Public Sub setStrokeWidth(Width As Int)

Update stroke width at runtime when this setting changes.

Original catalog note: Descripción: Obtiene o establece el grosor de las líneas o segmentos del gráfico.

Width As Int
Public Sub getStrokeWidth As Float

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

Returns: Float

Designer · 10

#DesignerProperty: Key: StrokeWidth, DisplayName: Stroke Width, FieldType: Int, DefaultValue: 10, Description: Width of the donut segments.#DesignerProperty: Key: InnerRadiusFactor, DisplayName: Inner Radius Factor, FieldType: Float, DefaultValue: 0.6, Description: Factor for inner radius (0 to 1).#DesignerProperty: Key: GapAngle, DisplayName: Gap Angle, FieldType: Int, DefaultValue: 5, Description: Angle of gap between segments (degrees).#DesignerProperty: Key: TitleText, DisplayName: Title Text, FieldType: String, DefaultValue: , Description: Title to display at the top.#DesignerProperty: Key: TitleTextSize, DisplayName: Title Text Size, FieldType: Int, DefaultValue: 16, Description: Font size of the title text.#DesignerProperty: Key: AnimationDuration, DisplayName: Animation Duration, FieldType: Int, DefaultValue: 2000, Description: Animation duration in milliseconds.#DesignerProperty: Key: UseGradients, DisplayName: Use Gradients, FieldType: Boolean, DefaultValue: False, Description: Use gradient colors for segments.#DesignerProperty: Key: PercentageSuffix, DisplayName: Percentage Suffix, FieldType: String, DefaultValue: %, Description: Suffix for percentage in legend.#DesignerProperty: Key: LegendTextColor, DisplayName: Legend Text Color, FieldType: Color, DefaultValue: 0xFF000000, Description: Color of the legend text.#DesignerProperty: Key: IsHalfDonut, DisplayName: Is Half Donut, FieldType: Boolean, DefaultValue: False, Description: Display as half donut (180 degrees).

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.

MouseClicked

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

B4A handler signature with Demo prefix

Private Sub Demo_MouseClicked()
    Log("MouseClicked")
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.