AnyChart
API Reference
Still have questions?
Contact support
Top

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:

NameTypeDescription
otherViewanychart.data.View | ArrayA 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.

filter

Creates a derived view, containing only the rows that pass the filter.

Params:

NameTypeDescription
fieldNamestringA field which value will be passed to a filter function.
filterFunctionfunction(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.

find

Searches fieldName by fieldValue and returns its index (or the first match).

Params:

NameTypeDescription
fieldNamestringName of the field.
fieldValue*Value of the field.

Returns:

number - Index in view.

get

Gets the value from the row by row index and field name.

Params:

NameTypeDescription
rowIndexnumberIndex of the row to get field value from.
fieldNamestringThe name of the field to be fetched from the current row.

Returns:

* - The field value or undefined, if not found.

getDataSets

Returns parent data sets.

Returns:

Array.<anychart.data.Set> - Parent data sets.

getIterator

Returns a new iterator for the current view.

Returns:

anychart.data.Iterator - New iterator.

getMapping

Gets the 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.

meta

Getter for a metadata value. Learn how it works at anychart.data.Iterator#meta.

Params:

NameTypeDescription
indexnumberRow index.
namestringName of the metadata field.

Returns:

* - Returns meta value.
Setter for a metadata value. Learn how it works at anychart.data.Iterator#meta.

Params:

NameTypeDescription
indexnumberRow index.
namestringName of the metadata field.
value*Value to set.

Returns:

anychart.data.Mapping - Self instance for method chaining.

row

Gets a full row of the set by an index.

Params:

NameTypeDescription
rowIndexnumberAn 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
Sets a row of the set by an index.

Params:

NameTypeDescription
rowIndexnumberAn 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

set

Sets the value to the row field by row index and field name.

Params:

NameTypeDescription
rowIndexnumberRow index to set.
fieldNamestringField name to set.
value*Value to set.

Returns:

anychart.data.Mapping - Itself for chaining.

sort

Creates a derived view that ensures sorting by a passed field.

Params:

NameTypeDescription
fieldNamestringA field name to make sort by.
comparatorfunction(value1:*, value2:*):numberA 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.
Creates a derived view that ensures sorting by a passed field.

Params:

NameTypeDefaultDescription
fieldNamestring
A field name to make sort by.
orderanychart.enums.Sort | string
'asc'
String value of anychart.enums.Sort|string enumeration except NONE.

Returns:

anychart.data.Mapping - The new derived sorted view.