Scale
Scales are a convenient abstraction for a fundamental task in visualization: mapping a dimension of abstract data to a visual representation. Different data types have different type of scales.
For continuous quantitative data, you typically want a linear scale.
For time series data, a timeCat scale
For discrete ordinal (ordered) or categorical (unordered) data, a cat scale specifies an explicit mapping from a set of data values to a corresponding set of visual attributes (such as colors, shapes).
A identity scale is for constant.
Scales have no intrinsic visual representation. However, most scales can generate and format ticks for reference marks to aid in the construction of axes.
F2 will generate scales for the data automatically. But still offers two methods to configure.Here is an example:
In the data, 'State' is a cat scale, 'Age' is a cat scale and 'Population' is a linear scale. Now we can set the maximum and minimum values of Population
Or
Common Configuration
The common configuration properties of scale are described below:
Name
Type
Default
Description
type
String
null
Specify the type of the scale, supported scale types are: identify
, linear
, cat
, timeCat
.
formatter
Function
null
It is used to format the text of the scale point in the axis and will affect the display of the data on axis, legend, and tooltip.
range
Array
[ 0, 1 ]
Used to control the drawing range of data on the coordinate, in the format of [ min, max ], and both min and max are data in the range 0 to 1.
alias
String
null
Alias of the data field, if it is set, we will display the alias
value in the chart.
tickCount
Number
Number of tick points in the axis, different scale types have different default values.
ticks
Array
null
Used to specify the scale text on the axis. When the user sets ticks, it will display according to ticks.
values
Array
null
Set the data collection of the scale, the default will automatically read from the data source, see Cat scale for detail usage.
Except for the above general configuration properties, different scale types have different configuration items.
Linear
Name
Type
Default
Description
nice
Boolean
true
used to optimize the range of values so that ticks on axes are evenly distributed. For example, the range [ 3, 97 ] will be optimized to [ 0, 100 ], if nice
is set to be true
.
min
Number
the minimum value of the data set
max
Number
the maximum value of the data set
tickInterval
Number
Used to specify the distance between the scale points of the axis, which is the difference between the original data. Note thattickCount
andtickInterval
cannot both be defined.
Cat
Cat scale has no other configuration items. But we will introduce the usage of values
here.
1. When you need to specify the display order of the categorical data.
We use the following data to draw a bar chart:
Now we can change the display order of the bar by setting values
, including legend:
After set this, the bar chart will be rendered as follow:
2. Convert index values to corresponding data. But the original value of the field must be indexed value, start from 0.
3. Control the display of data.
Case 1: we just have 3 items in data, but we can set 10 ticks on the axis:
Case 2: we just have 3 items in data, but we can just want to display one:
TimeCat
For time series data, we will sort the data set by default.
Name
Type
Default
Description
mask
String
'YYYY-MM-DD'
NOTE: mask
and formmater
cannot both be specified, if both are defined, the formatter
attribute will be used in priority.
Last updated