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 |
| String | null | Specify the type of the scale, supported scale types are: |
|
| 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. |
| 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. |
| String | null | Alias of the data field, if it is set, we will display the |
| Number | Number of tick points in the axis, different scale types have different default values. | |
| Array | null | Used to specify the scale text on the axis. When the user sets ticks, it will display according to ticks. |
| 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 |
| 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 |
| Number | the minimum value of the data set | |
| Number | the maximum value of the data set | |
| Number | Used to specify the distance between the scale points of the axis, which is the difference between the original data. Note that |
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 |
| 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