Public Sub Initialize (Callback As Object, EventName As String)
Prepare the instance before its other methods.
ELEVATEUI · B4A · XUI
Display proportional parts of a whole with room for a center label.
Charts & visualizations
Display proportional parts of a whole with room for a center label.
Animated conceptual demonstration, not an exact Android control screenshot.
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.
Tutorials are based on existing project examples or audited APIs. Check each example’s prerequisites; B4A compilation is not claimed.
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
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
21 audited signatures
Public Sub Initialize (Callback As Object, EventName As String)
Prepare the instance before its other methods.
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.
Public Sub SetData(listvalues As List, listlabels As List, listcolors As List)
Use SetData for its named operation; follow its exact signature.
Public Sub setTitleTextFont(Font As B4XFont)
Update title text font at runtime when this setting changes.
Public Sub setTitleTextSize(Size As Float)
Update title text size at runtime when this setting changes.
Public Sub setTitleText(Title As String)
Update title text at runtime when this setting changes.
Public Sub setTitleTextColor(Color1 As Int)
Update title text color at runtime when this setting changes.
Public Sub setLegendTextColor(Color1 As Int)
Update legend text color at runtime when this setting changes.
Public Sub setUseGradients(Value As Boolean)
Update use gradients at runtime when this setting changes.
Public Sub setPercentageSuffix(Suffix As String)
Update percentage suffix at runtime when this setting changes.
Public Sub setIconCenter(Text As String, Color1 As Int , font As B4XFont, size As Float)
Update icon center at runtime when this setting changes.
Public Sub setSubTextCenter(Text As String, Color1 As Int , font As B4XFont)
Update sub text center at runtime when this setting changes.
Public Sub SaveAsPNG(Dir As String, FileName As String) As Boolean
Use SaveAsPNG for its named operation; follow its exact signature.
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).
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.
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).
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.
Public Sub getStrokeWidth As Float
Read the current stroke width value for validation or UI synchronization.
Returns: Float
#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).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.
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 mBase As B4XView