AnyChart
API Reference
Still have questions?
Contact support
Top

class anychart.data.View Improve this Doc

Extends: anychart.core.Base

View is a representation of raw data.
Note: Default View is a view with default mapping.

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

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.View - 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.View - 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.View - 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.

getRowsCount

Returns the number of the rows in the current view.

Returns:

number - The number of the rows in the set.

listen

Adds an event listener to an implementing object.

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction(e:Object)
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
}
useCaptureboolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScopeObject
Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

listenOnce

Adds an event listener to an implementing object.

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction(e:Object)
Callback method.
useCaptureboolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScopeObject
Object in whose scope to call the listener.

Returns:

Object - Unique key for the listener.

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

removeAllListeners

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

Params:

NameTypeDescription
typestringType of event to remove, default is to remove all types.

Returns:

number - Number of listeners removed.

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]
 ]
 view.row(2); // returns [21, 22, 24, 27]
 view.row(3); // returns undefined
Sets a row of the set by an index.

Params:

NameTypeDescription
rowIndexnumberAn index of the row to fetch.
row*A row to set.

Returns:

* - Previous value of the row.
Example.
// Data
 [
   [1, 2, 4, 7],
   [11, 12, 14, 17],
   [21, 22, 24, 27]
 ]
 view.row(2, [2, 2, 2, 2]); // returns [21, 22, 24, 27]
 view.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.View - 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.View - 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.View - The new derived sorted view.

unlisten

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

Params:

NameTypeDefaultDescription
typestring
The event type id.
listenerfunction(e:Object):boolean|undefined
Callback method.
useCaptureboolean
false
Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing
listenerScopeObject
Object in whose scope to call the listener.

Returns:

boolean - Whether any listener was removed.

unlistenByKey

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

Params:

NameTypeDescription
keyObjectThe key returned by listen() or listenOnce().

Returns:

boolean - Whether any listener was removed.