Skip to main content

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.

Odometer or CountUp?

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​

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;
}

Properties​

PropertyDefaultWhat it does
Value0The number displayed, an integer. Changing it rolls the digits from the current value to the new one.
SkinDefaultThe look: Default, Car, Digital, Minimal, Plaza, SlotMachine or TrainStation (OdometerSkin).
FontSize13Size of the digits in pixels. 0 keeps the size the skin defines.
Duration750Length 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.

Set Duration before the control is shown

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:

public Page1()
{
InitializeComponent();
this.odometer1.OdometerDone += this.odometer1_OdometerDone;
}

private void odometer1_OdometerDone(object sender, EventArgs e)
{
AlertBox.Show("Total: " + this.odometer1.Value);
}
note

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​