Loading...
The function of join
is to connect two datasets together, similar to the JOIN
operation in SQL. This functionality is usually used to merge data from two data sources based on common fields, allowing records from two data sources to be combined according to specified conditions to form a new dataset. This functionality is very useful for displaying relational information between multiple data sources in visualizations. This operation is completed during the data preprocessing stage, and the newly generated fields can be directly used for graphic drawing, field mapping, annotations, and other operations.
Property | Description | Type | Default | Required |
---|---|---|---|---|
join | The data source to be joined | object[] | - | Yes |
on | Fields for connecting the two data sources | [string | ((d: any) => string), string | ((d: any) => string)] | - | Yes |
select | Fields to select from the joined data source | string[] | [] | No |
as | Rename the fields selected by select | string[] | No renaming | No |
unknown | Default value if no matching join data is found | any | NaN | No |
join
: Specifies the second data source to be joined, which can be an object array representing all join data.on
: Defines join conditions, passing in an array containing two fields or function arrays that can return field names. Used to match based on these fields in the two data sources.select
: Specifies which fields to select from the joined data source. Defaults to an empty array, meaning the joined data source contains all fields.as
: Specifies aliases for fields selected by select
. If not specified, defaults to the original field names.unknown
: When there is no matching data between the two data sources, use this value as the default value.📌 join can significantly enhance data organization capabilities in complex scenarios and is an indispensable tool for combining and cleaning data.
on: ['id', 'code'] // Or use function approach on: [(d) => d.id, (d) => d.code]
const data = [{ a: 1, b: 2, c: 3 },{ a: 4, b: 5, c: 6 },];const joinData = [{ c: 1, d: 2, e: 3 },{ c: 4, d: 5, e: 6 },];chart.options({data: {type: 'inline',value: data,transform: [{type: 'join',join: joinData,on: ['a', 'c'],select: ['d', 'e'],},],},});
[{ a: 1, b: 2, c: 3, d: 2, e: 3 },{ a: 4, b: 5, c: 6, d: 5, e: 6 },];
chart.options({data: {type: 'inline',value: data,transform: [{type: 'join',join: joinData,on: ['a', 'c'],select: ['d', 'e'],as: ['dd', 'ee'],},],},});
[{ a: 1, b: 2, c: 3, dd: 2, ee: 3 },{ a: 4, b: 5, c: 6, dd: 5, ee: 6 },];
const data = [{ id: 1 }, { id: 2 }];const joinData = [{ code: 1, label: 'A' }];chart.options({data: {type: 'inline',value: data,transform: [{type: 'join',join: joinData,on: ['id', 'code'],select: ['label'],unknown: 'Unknown',},],},});
[{ id: 1, label: 'A' },{ id: 2, label: 'Unknown' },];
join is a left join, meaning the main data is always retained.
When select is not specified, no fields are extracted by default, only used to determine join relationships.
It's recommended to deduplicate join data in advance to avoid ambiguity in many-to-one joins.
Supports dynamic functions to extract join fields, adapting to complex structures.