Top
You are looking at an outdated 7.12.0 version of this document. Switch to the 7.13.0 version to see the up to date information.

class anychart.data.Mapping Improve this Doc

Extends: anychart.data.View

Special view which allows to map 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 it index (or the first match).
get()Gets the value from the row by row index and field name.
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.
Events
listen()Adds an event listener.
listenOnce()Adds a single time event listener.
removeAllListeners()Removes all listeners.
unlisten()Removes the listener.
unlistenByKey()Removes the listener by the key.
Miscellaneous
getArrayMapping()Returns an array mapping.
getIndexMapping()Returns an index mapping.
getObjectMapping()Returns an object mapping.
getSimpleRowMapping()Returns a simple row 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.View - The new derived view.

derive

Creates a derived view, containing just the same data set and order as this view does.

Returns:

anychart.data.View - 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.
func function A filter function that should accept a field value and return true if the row should be included into the resulting view.

Returns:

anychart.data.View - The new derived view.

Try it:

find

Searches fieldName by fieldValue and returns it 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:

getArrayMapping

Returns an array mapping.

Returns:

Object.<Array.<number>> - Array mapping.

getIndexMapping

Returns an index mapping.

Returns:

Array.<string> - Index mapping.

getIterator

Returns a new iterator for the current view.

Returns:

anychart.data.Iterator - New iterator.

Try it:

getObjectMapping

Returns an object mapping.

Returns:

Object.<Array.<string>> - Object mapping.

getRowsCount

Returns the number of the rows in the current view.

Returns:

number - The number of the rows in the set.

Try it:

getSimpleRowMapping

Returns a simple row mapping.

Returns:

Array.<string> - Simple row mapping.

listen

Adds an event listener to an implementing object.

Params:

Name Type Description
type string The event type id.
listener function Callback method. Function that looks like function(event){ // event.actualTarget - actual event target // event.currentTarget - current event target // event.iterator - event iterator // event.originalEvent - original event // event.point - event point // event.pointIndex - event point index }.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope Object Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

Try it:

listenOnce

Adds an event listener to an implementing object.

Params:

Name Type Description
type string The event type id.
listener function Callback method.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope Object Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

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:

* - Current 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.View - Self instance for method chaining.

Try it:

removeAllListeners

Removes all listeners from an object. You can also optionally remove listeners of some particular type.

Params:

Name Type Description
type string Type of event to remove, default is to remove all types.

Returns:

number - Number of listeners removed.

Try it:

row

Gets a full row of the set by an index.

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.

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
fieldName string
value *

Returns:

anychart.data.View - 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 A sorting function that should accept two field values and return numeric result of the comparison.

Returns:

anychart.data.View - The new derived 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
'asc'
String value of anychart.enums.Sort enumeration except NONE.

Returns:

anychart.data.View - The new derived view.

Try it:

unlisten

Removes a listener added using listen() or listenOnce() methods.

Params:

Name Type Description
type string The event type id.
listener function Callback method.
useCapture boolean Whether to fire in capture phase (defaults to false).
listenerScope Object Object in whose scope to call the listener.

Returns:

boolean - Whether any listener was removed.

Try it:

unlistenByKey

Removes an event listener which was added with listen() by the key returned by listen() or listenOnce().

Params:

Name Type Description
key Object The key returned by listen() or listenOnce().

Returns:

boolean - Whether any listener was removed.

Try it: