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

class anychart.data.Set Improve this Doc

Extends: anychart.Base

Linear data storage.
Data is stored as an array or rows where each row contains several columns (see Listing 1 below). To start working with this storage you need to map columns using anychart.data.Set#mapAs method (you can create as many mappings as you like).
Each field can be a number, a string, a function, an array or an object. Data fields can of any type and they way you read them depends on mapping only: anychart.data.Set#mapAs. Sample mappings are shown in code samples 3, 4 and 5.
Note: To create an instance of this class use method anychart.data.set.

Methods Overview

Miscellaneous
append()Appends new rows to the set. Each argument is a row that will be appended to the Set.
data()Getter for the data in the Set.
getRowsCount()Returns the number of the rows in the current data set.
insert()Inserts the row to the set at the specified position.
mapAs()Defines data mapping.
remove()Removes the row by index.
row()Gets the full row of the set by the index.

Methods Description

append

Appends new rows to the set. Each argument is a row that will be appended to the Set.

Params:

Name Type Description
var_args * Rows to append.

Returns:

anychart.data.Set - anychart.data.Set instance for method chaining.

Try it:

data

Getter for the data in the Set.

Returns:

Array - Data array of the Set.
Setter for Set data.

Params:

Name Type Description
value Array A value to set.

Returns:

anychart.data.Set - The instance of anychart.data.Set class for method chaining.

getRowsCount

Returns the number of the rows in the current data set.

Returns:

number - The number of the rows in the set.

Try it:

insert

Inserts the row to the set at the specified position.

Params:

Name Type Default Description
row *
Row to insert.
index number
0
The index at which to insert the object. A negative index is counted from the end of an array.

Returns:

anychart.data.Set - anychart.data.Set instance for method chaining.

Try it:

mapAs

Defines data mapping.
You can define mappings for the different types of data (see samples). Default mapping is shown in anychart.data.Set constructor samples.

Params:

Name Type Default Description
arrayMapping Object.<Array.<number>>
{
  'x': [0],
  'value': [1, 0],
  'size': [2],
  'open': [1],
  'high': [2],
  'low': [3, 1],
  'close': [4]
}
Column mapping for the rows which are arrays.
objectMapping Object.<Array.<string>>
{'value': ['value', 'y', 'close']}
Column mapping for the rows which are objects.
defaultProps Array.<string>
['value', 'close']
The names of the fields to map to if a row is a string, number or a function. Does not work in cases when a row is an object.
indexProps Array.<string>
['x']
The names of the fields to be mapped to the current index if other options failed.

Returns:

anychart.data.Mapping - The instance of anychart.data.Mapping class for method chaining.

remove

Removes the row by index.

Params:

Name Type Description
index number Index of the row to remove.

Returns:

anychart.data.Set - anychart.data.Set instance for method chaining.

Try it:

row

Gets the full row of the set by the index.
Note: If there is no row for the index - returns undefined.

Params:

Name Type Description
rowIndex number The index of the row to fetch.

Returns:

* - The current row.

Try it:

Sets the row in the set by the index.
Note: Replaces the current value, previous values is returned but it is lost completely after that!

Params:

Name Type Description
rowIndex number The index of the row to fetch.
value * The value to set.

Returns:

* - The previous value of the row.