tickFormat method
Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values.
The specified count
should have the same value as the count that is used
to generate the ticks
.
final x = ScaleLinear(
domain: [0.1, 1],
range: ["red", "blue"],
interpolate: interpolateRgb,
);
final f = x.tickFormat();
f(0.1); // "0.1"
f(1); // "1.0"
An optional specifier allows a custom format (see FormatLocale
) where
the precision of the format is automatically set by the scale as
appropriate for the tick interval. For example, to format percentage
change, you might say:
var x = ScaleLinear(
domain: [-1, 1],
range: [0, 960],
interpolate: interpolateNumber,
);
var ticks = x.ticks(5),
tickFormat = x.tickFormat(5, "+%");
ticks.map(tickFormat); // ["-100%", "-50%", "+0%", "+50%", "+100%"]
If specifier
uses the format type s
, the scale will return a SI-prefix
format (see formatPrefix
) based on the largest value in the domain. If
the specifier
already specifies a precision, this method is equivalent
to FormatLocale.format
.
See also d4_scale.tickFormat.
Implementation
String Function(num) tickFormat([num count = 10, String? specifier]) {
var d = domain;
return d4_scale.tickFormat(d[0], d[d.length - 1], count, specifier);
}