class anychart.data.Mapping Improve this Doc
Extends: anychart.data.View
The special view which allows mapping anychart.data.Set storages.
Methods Overview
Data | |
concat() | Concatenates two views to make a derived view that contains rows from both views. |
derive() | Creates a derived view, containing just the same data set and order as this view does. |
filter() | Creates a derived view, containing only the rows that pass the filter. |
find() | Searches fieldName by fieldValue and returns its index (or the first match). |
get() | Gets the value from the row by row index and field name. |
getDataSets() | Returns parent data sets. |
getIterator() | Returns a new iterator for the current view. |
getRowsCount() | Returns the number of the rows in the current view. |
meta() | Metadata settings. |
row() | Row of the set by an index |
set() | Sets the value to the row field by row index and field name. |
sort() | Data sorting. |
Miscellaneous | |
getMapping() | Gets the mapping. |
Methods Description
concat
Concatenates two views to make a derived view that contains rows from both views.
Params:
Name | Type | Description |
---|---|---|
otherView | anychart.data.View | Array | A view, data set or even an array to concat with. |
Returns:
anychart.data.Mapping - The new derived concatenated view.derive
Creates a derived view, containing just the same data set and order as this view does.
Returns:
anychart.data.Mapping - The new derived view.Try it:
filter
Creates a derived view, containing only the rows that pass the filter.
Params:
Name | Type | Description |
---|---|---|
fieldName | string | A field which value will be passed to a filter function. |
filterFunction | function(val:*) | A filter function that should accept a field value and return true if the row should be included in the resulting view. |
Returns:
anychart.data.Mapping - The new derived filtered view.Try it:
find
Searches fieldName by fieldValue and returns its index (or the first match).
Params:
Name | Type | Description |
---|---|---|
fieldName | string | Name of the field. |
fieldValue | * | Value of the field. |
Returns:
number - Index in view.Try it:
get
Gets the value from the row by row index and field name.
Params:
Name | Type | Description |
---|---|---|
rowIndex | number | Index of the row to get field value from. |
fieldName | string | The name of the field to be fetched from the current row. |
Returns:
* - The field value or undefined, if not found.Try it:
getDataSets
Returns parent data sets.
Returns:
Array.<anychart.data.Set> - Parent data sets.getIterator
getMapping
Gets the mapping.
Returns the set mapping (from the anychart.data.Set#mapAs method) or the default mapping.
Returns the set mapping (from the anychart.data.Set#mapAs method) or the default mapping.
Returns:
Object.<Array.<(number|string)>> - Mapping.getRowsCount
Returns the number of the rows in the current view.
Returns:
number - The number of the rows in the set.Try it:
meta
Getter for a metadata value.
Learn how it works at anychart.data.Iterator#meta.
Params:
Name | Type | Description |
---|---|---|
index | number | Row index. |
name | string | Name of the metadata field. |
Returns:
* - Returns meta value.Try it:
Setter for a metadata value. Learn how it works at anychart.data.Iterator#meta.
Params:
Name | Type | Description |
---|---|---|
index | number | Row index. |
name | string | Name of the metadata field. |
value | * | Value to set. |
Returns:
anychart.data.Mapping - Self instance for method chaining.Try it:
row
Gets a full row of the set by an index.
Detailed description
Note: If there is no row with the given index, methods returns undefined.
Params:
Name | Type | Description |
---|---|---|
rowIndex | number | An index of the row to fetch. |
Returns:
* - The row. Example.
// Data [ [1, 2, 4, 7], [11, 12, 14, 17], [21, 22, 24, 27] ] mapping.row(2); // returns [21, 22, 24, 27] mapping.row(3); // returns undefined
Try it:
Sets a row of the set by an index.
Detailed description
Note: Previous value of a row is returned but it is lost completely after that!
Params:
Name | Type | Description |
---|---|---|
rowIndex | number | An index of the row to fetch. |
value | * | A value to set. |
Returns:
* - Previous value of the row. Example.
// Data [ [1, 2, 4, 7], [11, 12, 14, 17], [21, 22, 24, 27] ] mapping.row(2, [2, 2, 2, 2]); // returns [21, 22, 24, 27] mapping.row(3, {'low': 4, 'high': 11}); // returns undefined
Try it:
set
Sets the value to the row field by row index and field name.
Params:
Name | Type | Description |
---|---|---|
rowIndex | number | Row index to set. |
fieldName | string | Field name to set. |
value | * | Value to set. |
Returns:
anychart.data.Mapping - Itself for chaining.Try it:
sort
Creates a derived view that ensures sorting by a passed field.
Params:
Name | Type | Description |
---|---|---|
fieldName | string | A field name to make sort by. |
comparator | function(value1:*, value2:*):number | A sorting function that should accept two field values and return the numeric result of the comparison. |
Returns:
anychart.data.Mapping - The new derived sorted view.Try it:
Creates a derived view that ensures sorting by a passed field.
Params:
Name | Type | Default | Description |
---|---|---|---|
fieldName | string | A field name to make sort by. | |
order | anychart.enums.Sort | string | 'asc' | String value of anychart.enums.Sort|string enumeration except NONE. |
Returns:
anychart.data.Mapping - The new derived sorted view.Try it: