d3 speedometer

Content Type: Widget
Categories: Utility,User Interface,Data

Overview

d3 Speedometer shows any numeric value as an animated, speedometer-style gauge. Built on the popular react-d3-speedometer library, it draws a semi-circular dial split into coloured segments, with a needle that smoothly moves to the current value whenever it changes.


What makes this widget different is that every setting is bound to an attribute of your entity. The value, range, colours, segments, labels and even the needle animation can all be changed at runtime from a microflow, nanoflow or input field, without redesigning the page. One widget can therefore serve many dashboards, each with its own look.


Features

- Value, minimum and maximum bound to Integer attributes

- Any number of segments, with automatic colour gradient from a start colour to an end colour

- Custom colour per segment, as a simple comma-separated list

- Unequal segments at custom stop values, for thresholds such as red / amber / green zones

- Custom segment labels (text, colour, font size, inside or outside the ring) defined as JSON

- Current value text with a placeholder, for example "Speed: ${value} km/h"

- Value formatting with d3-format patterns, such as whole numbers, decimals or thousands separators

- 29 needle animation styles (linear, bounce, elastic and more), with adjustable duration and needle length

- Fixed width and height in px, em, cm and other units, or fluid width that fills its container

- Adjustable ring width, padding, text colour, font sizes and font weight

- Accessible: set an aria-label that screen readers announce

Documentation

Typical usage scenario

Use d3 Speedometer when users need to read one number at a glance and see right away whether it is good, average or critical. The widget shows the value as an animated speedometer gauge with coloured zones, so a meaning like "in the red" or "in the green" is clear without reading a table or a chart.

Common uses:

- KPI dashboards: performance scores, SLA compliance, sales against target, completion percentage.

- IoT and device monitoring: live speed, temperature, pressure, fuel or battery level.

- Quality and risk indicators: risk scores, customer satisfaction, error rates, shown against red / amber / green thresholds.

- Progress and capacity: storage usage, workload, occupancy.

Every setting is bound to an attribute, so one page can show gauges with different ranges, thresholds and colours per object, and they can change at runtime from microflows or nanoflows.

Features and limitations

Features

- Value, minimum and maximum bound to Integer attributes; the needle animates when the value changes.

- Any number of segments, with an automatic colour gradient from a start colour to an end colour.

- A custom colour for each segment (comma-separated list).

- Unequal segments at custom stop values, for thresholds.

- Custom segment labels (text, colour, font size, inside or outside the ring) defined as JSON.

- Value text with a placeholder, for example Speed: ${value} km/h.

- d3-format patterns for number formatting (whole numbers, decimals, thousands separators).

- 29 needle animation styles, with adjustable duration and needle length.

- Fixed size in px, em, ex, in, cm, mm, pt or pc, or a fluid width that fills its container.

- Adjustable ring width, padding, text colour, font sizes and font weight.

- An accessible aria-label for screen readers.

- Works in offline-capable web apps.

Limitations

- Web only; not available for native mobile apps.

- Value, minimum and maximum are Integer attributes; decimal values are not supported for them.

- Values of 0 or below are ignored and replaced by the default, so negative ranges (for example -50 to 50) are not possible.

- Every property must be bound to an attribute; you cannot type a fixed value in the widget properties.

- Segment colours, stops and labels are entered as text (comma-separated lists or JSON), not with a visual editor.

Dependencies

- Mendix Studio Pro 10.24.17 or a later 10.24 version.

Installation

1. Download mendix.Speedometer.mpk from the Marketplace, or from the GitHub release Version1.0.1.

2. Copy it into the widgets folder of your app (App > Show App Directory in Explorer).

3. In Studio Pro, press F4 (App > Synchronize App Directory).

4. The Speedometer widget now appears in the Toolbox.

Configuration

1. Create an entity with an Integer attribute for the value. Add attributes for any other settings you want to control, for example Integer attributes for minimum, maximum and segments, and String attributes for colours.

2. Place the Speedometer widget inside a data view, list view or snippet that has this entity as its context.

3. Open the widget properties and select an attribute for each setting you need. Properties are grouped into tabs: General, Dimensions, Segments, Colors, Needle, Labels.

4. Leave a property empty to use its default: range 0–1000, 5 segments, colours #FF471A to #33CC33, width and height 300 px, needle transition easeQuadInOut (500 ms).

Value formats for text properties

- Segment colours: #FF471A,#F6961E,#ECDB23,#AEE228,#6AD72D (no spaces)

- Custom segment stops: 0,500,800,1000 (must start at the minimum and end at the maximum)

- Custom segment labels:

[{"text":"Low","position":"Inside"},{"text":"Medium","position":"Inside"},{"text":"High","position":"Outside","color":"#C00000"}]

- Value text: Current speed: ${value} km/h

Known bugs

None

Report to https://github.com/bharathidas/d3_speedometer/issues

Frequently Asked Questions

Can I set a fixed value without creating an attribute?

No. Every property is bound to an attribute. Give the attribute a default value in the domain model if it never changes.

Why doesn't my gauge start at a negative number?

Values of 0 or below are ignored for the minimum, so negative ranges are not supported.

How do I show a unit such as km/h or %?

Set currentValueText to something like ${value} km/h.

How do I make the gauge fill its container?

Set fluidWidth to true. Width and height are then ignored.

How do I create red / amber / green zones?

Use customSegmentStops (for example 0,600,850,1000) together with segmentColors (for example red,orange,green).

Do my existing 1.0.0 widgets need to be reconfigured?

No. The widget definition is unchanged, so all settings are kept after the upgrade.

Does it work on native mobile?

No, it is for web profiles only.

Releases

Version: 1.0.1
Framework Version: 10.24.17
Release Notes:

## d3 Speedometer 1.0.1


Widget version: **1.0.1** (same as this GitHub release tag)


### Compatibility

- Mendix Studio Pro **10.24.17**

- Built with `@mendix/pluggable-widgets-tools` 10.16.0

- Rendering library react-d3-speedometer 2.2.1 (unchanged)


`Speedometer.xml` is byte-identical to 1.0.0, so existing widget instances keep their configuration. Source changes are lint-only; the package is now a minified production build (72 KB instead of 428 KB).


### Install

Download `mendix.Speedometer.mpk` from this release and import it into your Mendix app.


Sample module: download [`d3speedometer.mpk`](https://github.com/bharathidas/d3_speedometer/raw/Version1.0.1/d3speedometer.mpk) from the repository (Studio Pro 10.24.17, bundles widget 1.0.1), import it via *File > Import Module Package* and open `d3speedometer.Home_Web`.


### Known behavior (carried over from 1.0.0)

- Values of 0 or below are ignored for value, minValue, maxValue and the other numeric attributes, and the default is used instead. A negative minValue is therefore not possible.

- If customSegmentLabels is set while maxSegmentLabels is empty, the widget passes 0 and numeric segment labels render at `rotate(NaN)`, stacking at the center. Set maxSegmentLabels to the segment count to avoid this.


### Previous version (Mendix 9.12.4, widget 1.0.0)

- [Version1.0](https://github.com/bharathidas/d3_speedometer/releases/tag/Version1.0) — widget `mendix.Speedometer.mpk` 1.0.0

- [Version1.1](https://github.com/bharathidas/d3_speedometer/releases/tag/Version1.1) — sample app `d3_speedometer.mpk`


Version: 1.0.0
Framework Version: 9.24.12
Release Notes: Used for showing speedometer like gauge using d3. **Features** **General**: •**Value** - Make sure your value is between your minValue and maxValue. Default is 0 •**minValue** - Min Value. Default is 0 •**maxValue** - Max Value. Default is 1000 •**forceRender** - After initial rendering/mounting, when props change, only the value is changed and animated to maintain smooth visualization. But, if you want to force rerender the whole component like change in segments, colors, dimensions etc, you can use this option to force rerender of the whole component on props change. Default is true. •**currentValueText** - Should be provided a string which should have ${value} placeholder which will be replaced with current value. By default, current value is shown (formatted with valueFormat). For example, if current Value is 333 if you would like to show Current Value: 333, you should provide a string Current Value: ${value} •**currentValuePlaceholderStyle** - Should be provided a placeholder string which will be replaced with current value •**svgAriaLabel** - SVG aria-label property for Accessibility purposes. Default is "React d3 speedometer" **Dimensions**: •**Width** - diameter of the speedometer and the width of the svg element. Default is 300. •**Height** - height of the svg element. The height of the speedometer is always half the width since it is a semi-circle. Default is 300. •**dimension** Unit - Possible values - "em" , "ex" , "px" , "in" , "cm" , "mm" , "pt" , ,"pc". Default is "px" for width/height. •**fluidWidth** - If true takes the width of the parent component. Default is false. •**paddingHorizontal** - Provides right/left space for the label text. Takes a number (without explicit unit, unit will be taken from dimension Unit config which defaults to px). Helpful when using a bigger font size for label texts. Default is 0. •**paddingVertical** - Provides top/bottom space for the current value label text below the needle. Takes a number (without explicit unit, unit will be taken from dimensionUnit config which defaults to px). Helpful when using a bigger font size for label texts. Default is 0. •**ringWidth** - Width of the speedometer ring. Default is 60. **Segments**: •**segments** - Number of segments in the speedometer. •**maxSegmentLabels** - Limit the number of segment labels displayed. •**segmentColors** - Custom segment colors can be given with this option. Should be an array of valid color codes. If this option is given startColor and endColor options will be ignored. •**customSegmentStops** - Array of values starting at min value and ending at max value. This configuration is useful if you would like to split the segments at custom points or have unequal segments at preferred values. If the values do not begin and end with min and max value respectively, an error will be thrown. This configuration will override segments prop, since total number of segments will be length – 1 •**customSegmentLabels** - Takes an array of CustomSegmentLabel objects. Each object has the following keys for custom rendering of labels - text, fontSize, color, position: OUTSIDE/INSIDE. **Colors**: •**needleColor** - Should be a valid color code - colorname, hexadecimal name or rgb value. Default is "steelblue" •**startColor** - Should be a valid color code - colorname, hexadecimal name or rgb value. Default is "#FF471A" •**endColor** - Should be a valid color code - colorname, hexadecimal name or rgb value. Default is "#33CC33" **Needle**: •**needleTransition** - easeLinear, easeQuadIn, easeQuadOut, easeQuadInOut, easeCubicIn, easeCubicOut, easeCubicInOut, easePolyIn, easePolyOut, easePolyInOut, easeSinIn, easeSinOut, easeSinInOut, easeExpIn, easeExpOut, easeExpInOut, easeCircleIn, easeCircleOut, easeCircleInOut, easeBounceIn, easeBounceOut, easeBounceInOut, easeBackIn, easeBackOut, easeBackInOut, easeElasticIn, easeElasticOut, easeElasticInOut, easeElastic. Default is "easeQuadInOut" •**needleTransitionDuration** - Time in milliseconds. Default is 500. •**needleHeightRatio** - Control the height of the needle by giving a decimal between 0 and 1. Default height ratio is 0.9. Labels: •**textColor** - Should be a valid color code - color name, hexadecimal name or rgb value. Used for both showing the current value and the segment values. Default is #666 •**valueFormat** - should be a valid format for d3-format. By default, no formatter is used. You can use a valid d3 format identifier (for eg: d to convert float to integers), to format the values. Note: This formatter affects all the values (current value, segment values) displayed in the speedometer •**labelFontSize** - Font size for segment labels/legends. Default is 14px •**valueTextFontSize** - Font size for current value text. Default is 16px •**valueTextFontWeight** - Font weight for current value text. Any valid font weight identifier (500, bold etc.) can be used. Default is bold **Demo URL:** [https://d3-speedometer-sandbox.mxapps.io/login.html?profile=Responsive](https://d3-speedometer-sandbox.mxapps.io/login.html?profile=Responsive) demo_administrator VKrsc19rRtwY **Dependencies:** • Mendix modeler 9.12.4. **Issues, suggestions and feature requests** [https://github.com/bharathidas/d3_speedometer/issues](https://github.com/bharathidas/d3_speedometer/issues)