Stripped personal data from development repository
Samo Penic
2019-02-20 83c3f647c35477564b77cbc5b36d37d793d5442a
commit | author | age
83c3f6 1 # Options
SP 2
3 ## Scriptable Options
4
5 Scriptable options also accept a function which is called for each data and that takes the unique argument `context` representing contextual information (see [option context](options.md#option-context)).
6
7 Example:
8
9 ```javascript
10 color: function(context) {
11     var index = context.dataIndex;
12     var value = context.dataset.data[index];
13     return value < 0 ? 'red' :  // draw negative values in red
14         index % 2 ? 'blue' :    // else, alternate values in blue and green
15         'green';
16 }
17 ```
18
19 > **Note:** scriptable options are only supported by a few bubble chart options.
20
21 ## Indexable Options
22
23 Indexable options also accept an array in which each item corresponds to the element at the same index. Note that this method requires to provide as many items as data, so, in most cases, using a [function](#scriptable-options) is more appropriated if supported.
24
25 Example:
26
27 ```javascript
28 color: [
29     'red',    // color for data at index 0
30     'blue',   // color for data at index 1
31     'green',  // color for data at index 2
32     'black',  // color for data at index 3
33     //...
34 ]
35 ```
36
37 ## Option Context
38
39 The option context is used to give contextual information when resolving options and currently only applies to [scriptable options](#scriptable-options).
40
41 The context object contains the following properties:
42
43 - `chart`: the associated chart
44 - `dataIndex`: index of the current data
45 - `dataset`: dataset at index `datasetIndex`
46 - `datasetIndex`: index of the current dataset
47
48 **Important**: since the context can represent different types of entities (dataset, data, etc.), some properties may be `undefined` so be sure to test any context property before using it.