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:
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 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.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.View - 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
getRowsCount
Returns the number of the rows in the current view.
Returns:
number - The number of the rows in the set.Try it:
listen
Adds an event listener to an implementing object.
Detailed description
The listener can be added to an object once, and if it is added one more time, its key will be returned.
Note Notice that if the existing listener is one-off (added using listenOnce), it will cease to be such after calling the listen() method.
Note Notice that if the existing listener is one-off (added using listenOnce), it will cease to be such after calling the listen() method.
Params:
Name | Type | Default | Description |
---|---|---|---|
type | string | The event type id. | |
listener | function(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 } | |
useCapture | boolean | false | Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing |
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.
Detailed description
After the event is called, its handler will be deleted.
If the event handler being added already exists, listenOnce will do nothing.
Note In particular, if the handler is already registered using listen(), listenOnce() will not make it one-off. Similarly, if a one-off listener already exists, listenOnce will not change it (it wil remain one-off).
If the event handler being added already exists, listenOnce will do nothing.
Note In particular, if the handler is already registered using listen(), listenOnce() will not make it one-off. Similarly, if a one-off listener already exists, listenOnce will not change it (it wil remain one-off).
Params:
Name | Type | Default | Description |
---|---|---|---|
type | string | The event type id. | |
listener | function(e:Object) | Callback method. | |
useCapture | boolean | false | Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing |
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:
* - 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.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.
Detailed description
Note: If there is no row with the given index, methods returns undefined.
See sample at anychart.data.Set#row
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] ] view.row(2); // returns [21, 22, 24, 27] view.row(3); // returns undefined
Try it:
Sets a row of the set by an index.
Detailed description
Note: The 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. |
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
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.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(value1:*, value2:*):number | A 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.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.View - The new derived sorted view.Try it:
unlisten
Removes a listener added using listen() or listenOnce() methods.
Params:
Name | Type | Default | Description |
---|---|---|---|
type | string | The event type id. | |
listener | function(e:Object):boolean|undefined | Callback method. | |
useCapture | boolean | false | Whether to fire in capture phase. Learn more about capturing https://javascript.info/bubbling-and-capturing |
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: