Skip to content

Commit 44908f5

Browse files
authored
Update docs (#12037)
* Update docs Grammar and style: "TypeScript", add articles, etc. Add docs covering the `Array[]` version of data. Please review and let me know if I've made any mistakes. Fix an apparent mistake in the `parsing: false` description of category axes: I believe it's trying to say that _strings_ would be a mistake. * Reword based on feedback and further testing
1 parent 32c8032 commit 44908f5

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

docs/general/data-structures.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
The `data` property of a dataset can be passed in various formats. By default, that `data` is parsed using the associated chart type and scales.
44

5-
If the `labels` property of the main `data` property is used, it has to contain the same amount of elements as the dataset with the most values. These labels are used to label the index axis (default x axes). The values for the labels have to be provided in an array.
6-
The provided labels can be of the type string or number to be rendered correctly. In case you want multiline labels you can provide an array with each line as one entry in the array.
5+
If the `labels` property of the main `data` property is used, it has to contain the same amount of elements as the dataset with the most values. These labels are used to label the index axis (default `x` axis). The values for the labels have to be provided in an array.
6+
The provided labels can be of the type string or number to be rendered correctly. If you want multiline labels, you can provide an array with each line as one entry in the array.
77

88
## Primitive[]
99

@@ -19,7 +19,22 @@ const cfg = {
1919
}
2020
```
2121

22-
When the `data` is an array of numbers, values from `labels` array at the same index are used for the index axis (`x` for vertical, `y` for horizontal charts).
22+
When `data` is an array of numbers, values from the `labels` array at the same index are used for the index axis (`x` for vertical, `y` for horizontal charts).
23+
24+
## Array[]
25+
26+
```javascript
27+
const cfg = {
28+
type: 'line',
29+
data: {
30+
datasets: [{
31+
data: [[10, 20], [15, null], [20, 10]]
32+
}]
33+
}
34+
}
35+
```
36+
37+
When `data` is an array of arrays (or what TypeScript would call tuples), the first element of each tuple is the index (`x` for vertical, `y` for horizontal charts) and the second element is the value (`y` by default).
2338

2439
## Object[]
2540

@@ -58,7 +73,9 @@ const cfg = {
5873

5974
This is also the internal format used for parsed data. In this mode, parsing can be disabled by specifying `parsing: false` at chart options or dataset. If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.
6075

61-
The values provided must be parsable by the associated scales or in the internal format of the associated scales. A common mistake would be to provide integers for the `category` scale, which uses integers as an internal format, where each integer represents an index in the labels array. `null` can be used for skipped values.
76+
The values provided must be parsable by the associated scales or in the internal format of the associated scales. For example, the `category` scale uses integers as an internal format, where each integer represents an index in the labels array; but, if parsing is enabled, it can also parse string labels.
77+
78+
`null` can be used for skipped values.
6279

6380
## Object[] using custom properties
6481

@@ -117,7 +134,7 @@ const cfg = {
117134
```
118135

119136
:::warning
120-
When using object notation in a radar chart, you still need a labels array with labels for the chart to show correctly.
137+
When using object notation in a radar chart, you still need a `labels` array with labels for the chart to show correctly.
121138
:::
122139

123140
## Object
@@ -136,7 +153,7 @@ const cfg = {
136153
}
137154
```
138155

139-
In this mode, property name is used for `index` scale and value for `value` scale. For vertical charts, index scale is `x` and value scale is `y`.
156+
In this mode, the property name is used for the `index` scale and value for the `value` scale. For vertical charts, the index scale is `x` and value scale is `y`.
140157

141158
## Dataset Configuration
142159

@@ -180,9 +197,9 @@ const cfg = {
180197
};
181198
```
182199

183-
## Typescript
200+
## TypeScript
184201

185-
When using typescript, if you want to use a data structure that is not the default data structure, you will need to pass it to the type interface when instantiating the data variable.
202+
When using TypeScript, if you want to use a data structure that is not the default data structure, you will need to pass it to the type interface when instantiating the data variable.
186203

187204
```ts
188205
import {ChartData} from 'chart.js';

0 commit comments

Comments
 (0)