ECharts Data Visual Mapping
In simple terms, data visualization is presenting data in the form of charts; the professional description is the mapping process from data to visual elements.
Each ECharts chart type has this mapping process built in; for example, the bar chart we learned about earlier maps data onto length.
In addition, ECharts provides the visualMap component to deliver general visual mapping. The visual elements that can be used in the visualMap component are:
- Symbol category (symbol)
- Symbol size (symbolSize)
- Color (color)
- Opacity (opacity)
- Color alpha (colorAlpha)
- Color lightness (colorLightness)
- Color saturation (colorSaturation)
- Color hue (colorHue)
Data and Dimensions
Data in ECharts is generally stored in series.data it.
Different chart types use different data formats, but they share the common trait of all being collections of data items (dataItem). Each data item contains a data value (value) and other information (optional). Each data value can be a single number (one dimension) or an array (multiple dimensions).
The most common form of series.data is a linear list, that is, an ordinary array:
series
:
{
data
:
[
{
// Here, each item is a data item (dataItem)
value
:
2323
,
// This is the data value of the data item (value)
itemStyle
:
{
...
}
}
,
1212
,
// It can also be directly the value of a dataItem, which is more common.
2323
,
// Each value is 'one-dimensional'.
4343
,
3434
]
}
series
:
{
data
:
[
{
// Here, each item is a data item (dataItem)
value
:
[
3434
,
129
,
'San Marino'
]
,
// This is the data value of the data item (value)
itemStyle
:
{
...
}
}
,
[
1212
,
5454
,
'Vatican City'
]
,
// It can also be directly the value of a dataItem, which is more common.
[
2323
,
3223
,
'Nauru'
]
,
// Each value is 'three-dimensional', and each column is a dimension.
[
4343
,
23
,
'Tuvalu'
]
// If it is a 'bubble chart', commonly the first dimension is mapped to the x-axis,
// the second dimension is mapped to the y-axis,
// and the third dimension is mapped to the bubble radius (symbolSize)
]
}
In charts, the first one or two dimensions of value are usually mapped by default; for example, the first dimension is mapped to the x-axis and the second to the y-axis. To reveal more dimensions, you can use visualMap.
visualMap Component
The visualMap component defines how a specified dimension of the data is mapped onto the corresponding visual element.
Multiple visualMap components can be defined, so that multiple dimensions of the data can be visually mapped at the same time.
The visualMap component can be defined as piecewise (visualMapPiecewise) or continuous (visualMapContinuous), distinguished by type. For example:
option
=
{
visualMap
:
[
{
// The first visualMap component
type
:
'continuous'
,
// Defined as a continuous visualMap
...
}
,
{
// The second visualMap component
type
:
'piecewise'
,
// Defined as a piecewise visualMap
...
}
]
,
...
}
;
The piecewise visual mapping component has three modes:
- Average segmentation of continuous data: it is automatically split into several blocks on average according to visualMap-piecewise.splitNumber.
- Custom segmentation of continuous data: the range of each block is defined according to visualMap-piecewise.pieces.
- Segmentation of discrete data by category: the categories are defined in visualMap-piecewise.categories.
The piecewise visual mapping component is presented as shown in the figure below:
Example
Try it »
Configuration of Visual Mapping
In visualMap, you can specify that a designated dimension of the data is mapped to the corresponding visual element.
Example 1
option
=
{
visualMap
:
[
{
type
:
'piecewise'
min
:
0
,
max
:
5000
,
dimension
:
3
,
// The fourth dimension of series.data (i.e., value[3]) is mapped
seriesIndex
:
4
,
// Mapping is applied to the fourth series.
inRange
:
{
// Visual configuration within the selected range
color
:
[
'blue'
,
'#121122'
,
'red'
]
,
// Defines the color list for the graphic color mapping,
// The minimum data value is mapped to 'blue',
// the maximum value is mapped to 'red',
// and the rest are computed automatically in a linear manner.
symbolSize
:
[
30
,
100
]
// Defines the mapping range of the graphic size,
// The minimum data value is mapped to 30,
// the maximum value is mapped to 100,
// and the rest are computed automatically in a linear manner.
}
,
outOfRange
:
{
// Visual configuration outside the selected range
symbolSize
:
[
30
,
100
]
}
}
,
...
]
}
;
Example 2
option
=
{
visualMap
:
[
{
...
,
inRange
:
{
// Visual configuration within the selected range
colorLightness
:
[
0.2
,
1
]
,
// Mapped to lightness. That is, the original color is adjusted in lightness.
// The original color may be chosen from the global palette; the visualMap component does not concern itself with it.
symbolSize
:
[
30
,
100
]
}
,
...
}
,
...
]
}
;
For more details, see visualMap.inRange and visualMap.outOfRange.
