Odometer
Odometer displays an integer and animates every change by rolling each digit to its new position, like the mileage counter in a car or a departure board at a station. It reads well for running totals, such as visitors, units produced or tickets sold, where the reader should notice that the number moved.
It wraps HubSpot's Odometer library, along with its seven CSS skins.
Both animate a changing number. CountUp counts through the intermediate values in a normal label, with your own font, culture-aware separators and optional custom numerals. Odometer rolls the digits mechanically and draws them with its own skin. Pick CountUp for a number that should blend with the page, and Odometer for a counter that should look like a device.
Installation
dotnet add package Wisej-4-Odometer
The package targets .NET Framework 4.8 and .NET 8 (including the -windows, Android, iOS and Mac Catalyst targets). After a rebuild, Odometer appears in the Visual Studio toolbox.
Getting started
- C#
- VB.NET
using Wisej.Web.Ext.Odometer;
var odometer1 = new Odometer
{
Skin = OdometerSkin.Digital,
Duration = 1000,
FontSize = 32,
Value = 100
};
this.Controls.Add(odometer1);
// Every change rolls the digits to the new value.
private void button1_Click(object sender, EventArgs e)
{
this.odometer1.Value += 10;
}
Imports Wisej.Web.Ext.Odometer
Dim odometer1 As New Odometer With {
.Skin = OdometerSkin.Digital,
.Duration = 1000,
.FontSize = 32,
.Value = 100
}
Me.Controls.Add(odometer1)
' Every change rolls the digits to the new value.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.Odometer1.Value += 10
End Sub
Properties
| Property | Default | What it does |
|---|---|---|
Value | 0 | The number displayed, an integer. Changing it rolls the digits from the current value to the new one. |
Skin | Default | The look: Default, Car, Digital, Minimal, Plaza, SlotMachine or TrainStation (OdometerSkin). |
FontSize | 13 | Size of the digits in pixels. 0 keeps the size the skin defines. |
Duration | 750 | Length of the roll, in milliseconds. |
The control's default size is 100 × 40 pixels. The skin draws the digits, so Font, ForeColor and BackColor have no effect. Size the digits with FontSize. The control can't take focus and isn't part of the tab order.
Duration is passed to the Odometer library when the widget is created in the browser. Changing it later doesn't affect an odometer that's already on screen.
Knowing when the roll ends
OdometerDone is called when the digits have reached the new value. It's a public EventHandler field rather than a declared event, so it isn't listed in the designer's events and it isn't in the API reference. Attach it in code:
- C#
- VB.NET
public Page1()
{
InitializeComponent();
this.odometer1.OdometerDone += this.odometer1_OdometerDone;
}
private void odometer1_OdometerDone(object sender, EventArgs e)
{
AlertBox.Show("Total: " + this.odometer1.Value);
}
Public Sub New()
InitializeComponent()
Me.Odometer1.OdometerDone = AddressOf Odometer1_OdometerDone
End Sub
Private Sub Odometer1_OdometerDone(sender As Object, e As EventArgs)
AlertBox.Show("Total: " & Me.Odometer1.Value)
End Sub
Because OdometerDone is a field, VB.NET can't use AddHandler or Handles with it. Assign the handler as shown. To attach more than one, combine them with [Delegate].Combine.
API reference
OdometerOdometerSkin- The whole
Wisej.Web.Ext.Odometernamespace