18 Oct 202124 minutes to read

The `radial axis` is a circular arc in which a set of values are displayed along a linear or custom scale based on the design requirements. Axis elements such as labels, ticks, and axis line can be easily customized with built-in properties.

## Axis Customization

Axis minimum and maximum

The `minimum` and `maximum` properties of an axis can be used to customize the axis range.The default value of `minimum` is 0, and the default value of `maximum` is 100.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
)
]
),
),
);
}``````

Angle Customization

The start and end angles of radial axis can be customized using the `startAngle` and `endAngle` properties.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
)
]
),
),
);
}``````

The radius of the radial axis can be customized using the `radiusFactor` property. The default value of the `radiusFactor` is 0.95. The value of `radiusFactor` ranges from 0 to 1. For example, When the `radiusFactor` value is 1, the full radius will be considered for rendering the axis, and when the `radiusFactor` value is 0.5, then half of the radius value will be considered for rendering the circle.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

Axis position customization

The position of the `radial axis` can be customized using the `centerX` and `centerY` values. The default value of `centerX` and `centerY` properties is 0.5. Therefore, the axis will be positioned in the center of provided size of gauge.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
endAngle: 270, interval: 20
)
]
),
),
);
}``````

Positioning axis based on its angle

The `canScaleToFit` property of `radial axis` allows to position the axis and its features based on the provided `start` and `end angle`. By default, the `canScaleToFit` is false, therefore the axis will be positioned based on the `centerX` and `centerY` value.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
interval: 10,
canScaleToFit: true)]),
),
);
}``````

Axis label rotation

The axis label can be rotated based on its current angle using the `canRotateLabels` property of axis. The default value of `canRotateLabels` is false.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

Edge label customization

The visibility of the first and last labels of an axis can be customized using the `showFirstLabel` and `showLastLabel` properties.

The default value of both the `showFirstLabel` and the `showLastLabel` properties is true.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
startAngle: 270, endAngle: 270, minimum: 0, maximum: 12),
]
),
),
);
}``````

Axis direction customization

The direction of `radial axis` can be customized by its `isInversed` property.

When the `isInversed` property is true, the axis can be placed in counter-clockwise direction. When the `isInversed` property is set to false, the axis will be positioned in clockwise direction.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

Maximum number of labels per 100 logical pixels

By default, a maximum of three labels are displayed for each 100 logical pixels in an axis. The maximum number of labels that should present within 100 logical pixels length can be customized using the `maximumLabels` property of the axis. This property is applicable only for automatic range calculation and will not work if you set value for interval property of an axis.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

Interval

The interval between labels can be customized using the `interval` property of axis.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

Axis line customization

The radial axis line can be customized using the `axisLineStyle` property. The following properties can be customized using `axisLineStyle`.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
axisLineStyle: AxisLineStyle(thickness: 0.1,
thicknessUnit: GaugeSizeUnit.factor, color: Colors.deepPurple,)),
]
),
),
);
}``````

Rounded Corners

The `cornerStyle` property of `axisLineStyle` specifies the corner type for axis line. The corners can be customized using the bothFlat, bothCurve, startCurve, and endCurve options. The default value of this property is bothFlat.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
cornerStyle:CornerStyle.bothCurve)),
]
),
),
);
}``````

Dashed axis line

The `dashArray` property of `axisLineStyle` allows to render the dashed axis line.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
axisLineStyle: AxisLineStyle( dashArray: <double>[5,5])),
]
),
),
);
}``````

The `gradient` property of `axisLineStyle` allows to specify the smooth color transition to the axis line by specifying the different colors based on provided factor value.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
axisLineStyle: AxisLineStyle(thickness: 0.1,
thicknessUnit: GaugeSizeUnit.factor,
colors: <Color>[Color(0xFFFF7676), Color(0xFFF54EA2)],
stops: <double>[0.25, 0.75]
),
)
),
]
),
),
);
}``````

Axis line visibility

The visibility of the axis line can be customized using the `showAxisLine` property of axis. By default, this property is set to true.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

Background color support

`Radial gauge` allows customizing its background color using `backgroundColor` property.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
backgroundColor: Colors.lightBlue,
)),
);
}``````

Background image support

`Radial axis` allows to add an image frame as its background using `backgroundImage` property.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
showLastLabel: false,
canRotateLabels: true,
tickOffset: 0.32,
offsetUnit: GaugeSizeUnit.factor,
onLabelCreated: axisLabelCreated,
startAngle: 270,
endAngle: 270,
labelOffset: 0.05,
maximum: 360,
minimum: 0,
interval: 30,
minorTicksPerInterval: 4,
axisLabelStyle: GaugeTextStyle(color: const Color(0xFF949494)),
minorTickStyle: MinorTickStyle(color: const Color(0xFF616161),
thickness: 1.6,
length: 0.058,
lengthUnit: GaugeSizeUnit.factor),
majorTickStyle: MajorTickStyle(color: const Color(0xFF949494),
thickness: 2.3,
length: 0.087,
lengthUnit: GaugeSizeUnit.factor),
backgroundImage: const AssetImage(
'images/dark_theme_gauge.png'),
pointers: <GaugePointer>[
MarkerPointer(value: 90,
color: const Color(0xFFDF5F2D),
enableAnimation: true,
animationDuration: 1200,
markerOffset: 0.71,
offsetUnit: GaugeSizeUnit.factor,
markerType: MarkerType.triangle,
markerHeight: 10,
markerWidth: 15)
],
annotations: <GaugeAnnotation>[
GaugeAnnotation(angle: 270,
positionFactor:  0.025,
widget: Text('90',
style: TextStyle(
color: const Color(0xFFDF5F2D),
fontWeight: FontWeight.bold,
fontSize: 22
)
)
)
]
)
],
),
)
),
);
}

void axisLabelCreated(AxisLabelCreatedArgs args) {
if (args.text == '90') {
args.text = 'E';
args.labelStyle = GaugeTextStyle(
color: const Color(0xFFDF5F2D));
}else{
if (args.text == '0') {
args.text = 'N';
}else if (args.text == '180') {
args.text = 'S';
} else if (args.text == '270') {
args.text = 'W';
}

args.labelStyle = GaugeTextStyle(
color: const Color(0xFFFFFFFF),
);
}
}``````

## Label style customization

The axis labels can be customized using the `axisLabelStyle` property of axis. The following properties can be customized using the `axisLabelStyle`.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
color: Colors.red, fontSize: 15,
fontStyle:FontStyle.italic,
fontWeight: FontWeight.bold, fontFamily: 'Times') ),
]
),
),
);
}``````

Formatting axis label

The following property of the axis allows to customize the axis label text.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
numberFormat: NumberFormat.compactSimpleCurrency()),
]
),
),

);
}``````

Label visibility

The `showLabels` property of axis allows to enable or disable the visibility of labels. The default value of the property is true.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

## Tick customization

The major and minor tick lines of an axis can be customized using the `majorTickStyle` and `minorTickStyle` properties respectively. The following properties can be customized for both the major and the minor ticks:

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
lengthUnit: GaugeSizeUnit.factor, thickness: 1.5, color: Colors.black),
minorTickStyle: MinorTickStyle(length: 0.05,
lengthUnit: GaugeSizeUnit.factor, thickness: 1.5, color: Colors.black)
)]
),
),
);
}``````

Dashed tick lines

The `dashArray` property of both the `majorTickStyle` and `minorTickStyle` allows to draw the tick line as dashed line.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
majorTickStyle: MajorTickStyle(length: 20, dashArray: <double>[5,2.5]),
minorTickStyle: MinorTickStyle(length: 15, dashArray: <double>[3,2.5])),
]
),
),
);
}``````

Minor tick interval

The major ticks are generated based on the `interval` property. Like major ticks, the minor ticks are calculated using the `minorTicksPerInterval` property of axis. By default, the value of this property is 1.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
]
),
),
);
}``````

Tick line visibility

The `showTicks` property of the axis is used to enable or disable the visibility of both the major and the minor ticks of axis. The default value of this property is true.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
),
),
);
}``````

Label and tick Placement

The `radial axis` allows to position the labels and ticks either inside or outside the axis line using the `labelsPosition` and `ticksPosition` properties. By default, both labels and ticks are positioned inside the axis line.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
labelsPosition: ElementsPosition.outside,
ticksPosition: ElementsPosition.outside)]
),
),
);
}``````

Tick position customization

The ticks can be moved near or far to the axis line using the `tickOffset` property. The `offsetUnit` property of axis allows to specify the tick offset either in factor or logical pixels, and the default value of `offsetUnit` is logicalPixel.

The default value of tick offset is 0. While setting offset for the ticks, the axis labels are also moved along with the ticks.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
tickOffset: 20)]
),
),
);
}``````

The following code example shows how to add tick offset with the `offsetUnit` property of axis.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
labelOffset: 0.2, offsetUnit: GaugeSizeUnit.factor
),
]
),
),
);
}``````

Label position customization

The `labelOffset` property allows to adjust the distance between the tick end and the labels. The `offsetUnit` property of axis allows to specify the label offset either in factor or logical pixels. By default, the value of the label offset is 15.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
labelOffset: 0.3, offsetUnit: GaugeSizeUnit.factor
),
]
),
),
);
}``````

The `offsetUnit` property of axis is common for both the `tickOffset` and `labelOffset`.

NOTE

`GaugeSizeUnit` allows to specify the value either in logical pixels or in factor. GaugeSizeUnit.factor ranges from 0 to 1. For example, when setting factor as 0.5, the half of axis radius value will be considered.

## Multiple axis

The `Radial Gauge` allows you to add n number of radial axis in its axes collection. You can also customize individual axis added in the `axes` collection.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
ticksPosition: ElementsPosition.outside,
labelsPosition: ElementsPosition.outside,

minorTicksPerInterval: 5,
minorTickStyle: MinorTickStyle(thickness: 1.5,
color: Color.fromARGB(255, 143, 20, 2),
length: 0.07, lengthUnit: GaugeSizeUnit.factor),
majorTickStyle: MinorTickStyle(thickness: 1.5,
color: Color.fromARGB(255, 143, 20, 2),
length: 0.15, lengthUnit: GaugeSizeUnit.factor,),
axisLineStyle: AxisLineStyle( thickness: 3,
color: Color.fromARGB(255, 143, 20, 2), ),
axisLabelStyle: GaugeTextStyle(fontSize: 12,
color:Color.fromARGB(255, 143, 20, 2),),),

RadialAxis(minimum:  0 , maximum: 60, interval: 10,
radiusFactor:  0.6, labelOffset: 15, isInversed: true,
minorTicksPerInterval: 5,
minorTickStyle: MinorTickStyle(color: Colors.black, thickness: 1.5,
lengthUnit: GaugeSizeUnit.factor, length: 0.07),
majorTickStyle: MajorTickStyle(color: Colors.black, thickness: 1.5,
lengthUnit: GaugeSizeUnit.factor, length: 0.15),
axisLineStyle: AxisLineStyle(color: Colors.black, thickness: 3, ),
axisLabelStyle: GaugeTextStyle(color:  Colors.black, fontSize: 12)),
],
)
),
);
}``````

## Events

onLabelCreated

The `onLabelCreated` event is called when an axis label is created. The following properties can be customized for the corresponding axis label when this event args:

NOTE

If both `axisLabelStyle` property of radial axis and `labelStyle` property of the `onLabelCreated` event args are set, the values of the `labelStyle` property of the event args will take precedence.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
onLabelCreated:axisLabelCreated,),
]
),
),
);
}

void axisLabelCreated(AxisLabelCreatedArgs args){
if(args.text == '100'){
args.labelStyle = GaugeTextStyle(color: Colors.red,fontStyle: FontStyle.italic,
fontFamily: 'Times', fontWeight: FontWeight.bold, fontSize: 15);
args.canRotate = true;
args.text = '100 %';
}
}``````

onAxisTapped

The `onAxisTapped` event is called when an axis is tapped. The corresponding axis value at the tapped position will be got from the event.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
onAxisTapped: axisTapped),
]
),
),
);
}

void axisTapped(double _tappedValue){

}``````

## Custom scale

`Radial gauge` allows you to display a set of values along with a custom scale based on your business logic using the `onCreateAxisRenderer` event of the axis. The `onCreateAxisRenderer` event allows returning the custom renderer for the axis. In that, we can override methods of `RadialAxisRenderer` to create the custom axis.

• DART
• ``````@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
minimum: 0,
maximum: 150,
onCreateAxisRenderer: () {
final CustomAxisRenderer renderer = CustomAxisRenderer();
return renderer;
},
)
]),
),
);
}

_CustomAxisRenderer() : super();

/// Generated the 9 non-linear interval labels from 0 to 150
/// instead of actual generated labels.
@override
List<CircularAxisLabel> generateVisibleLabels() {
final List<CircularAxisLabel> _visibleLabels = <CircularAxisLabel>[];
for (num i = 0; i < 9; i++) {
final double _value = _calculateLabelValue(i);
final CircularAxisLabel label = CircularAxisLabel(
this.axis.axisLabelStyle, _value.toInt().toString(), i, false);
label.value = _value;
}

return _visibleLabels;
}

/// Returns the factor(0 to 1) from value to place the labels in an axis.
@override
double valueToFactor(double value) {
if (value >= 0 && value <= 2) {
return (value * 0.125) / 2;
} else if (value > 2 && value <= 5) {
return (((value - 2) * 0.125) / (5 - 2)) + (1 * 0.125);
} else if (value > 5 && value <= 10) {
return (((value - 5) * 0.125) / (10 - 5)) + (2 * 0.125);
} else if (value > 10 && value <= 20) {
return (((value - 10) * 0.125) / (20 - 10)) + (3 * 0.125);
} else if (value > 20 && value <= 30) {
return (((value - 20) * 0.125) / (30 - 20)) + (4 * 0.125);
} else if (value > 30 && value <= 50) {
return (((value - 30) * 0.125) / (50 - 30)) + (5 * 0.125);
} else if (value > 50 && value <= 100) {
return (((value - 50) * 0.125) / (100 - 50)) + (6 * 0.125);
} else if (value > 100 && value <= 150) {
return (((value - 100) * 0.125) / (150 - 100)) + (7 * 0.125);
} else {
return 1;
}
}

/// To return the label value based on interval
double _calculateLabelValue(num value) {
if (value == 0) {
return 0;
} else if (value == 1) {
return 2;
} else if (value == 2) {
return 5;
} else if (value == 3) {
return 10;
} else if (value == 4) {
return 20;
} else if (value == 5) {
return 30;
} else if (value == 6) {
return 50;
} else if (value == 7) {
return 100;
} else {
return 150;
}
}
}``````