You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -83,11 +83,27 @@ While this may feel heavy at first, it gives you, the dev, full control over whe
83
83
84
84
## Data Model
85
85
86
-
React Charts uses a common and very flexible data model based on arrays of **series** and arrays of **datums**. You can either use the model defaults directly, or use **data accessors** to materialize this structure.
87
-
88
-
Typical visualization data can come in practically any shape and size. The following examples show data structures that are all reasonably equivalent **at some level** since they each contain an array of **series[]** and **datums[]**. They also show how to parse that data.
86
+
React Charts uses a data shape based on **arrays of series and nested arrays of datums in those series**.
87
+
88
+
```js
89
+
// series array
90
+
constdata= [
91
+
{
92
+
// individual series
93
+
label:'Purchases',
94
+
// datum array
95
+
data: [
96
+
{
97
+
// individual datum
98
+
primary:'Apples', // primary value
99
+
secondary:20, // secondary value
100
+
},
101
+
],
102
+
},
103
+
]
104
+
```
89
105
90
-
In the following example, there is no need to use any accessors. The **default** accessors are able to easily understand this format:
106
+
Visualization data can come in practically any shape and size, so **memoization of data into this shape is almost always necessary**.
91
107
92
108
```javascript
93
109
functionMyChart() {
@@ -96,25 +112,25 @@ function MyChart() {
96
112
{
97
113
label:'Series 1',
98
114
data: [
99
-
{ x:1, y:10 },
100
-
{ x:2, y:10 },
101
-
{ x:3, y:10 },
115
+
{ primary:1, secondary:10 },
116
+
{ primary:2, secondary:10 },
117
+
{ primary:3, secondary:10 },
102
118
],
103
119
},
104
120
{
105
121
label:'Series 2',
106
122
data: [
107
-
{ x:1, y:10 },
108
-
{ x:2, y:10 },
109
-
{ x:3, y:10 },
123
+
{ primary:1, secondary:10 },
124
+
{ primary:2, secondary:10 },
125
+
{ primary:3, secondary:10 },
110
126
],
111
127
},
112
128
{
113
129
label:'Series 3',
114
130
data: [
115
-
{ x:1, y:10 },
116
-
{ x:2, y:10 },
117
-
{ x:3, y:10 },
131
+
{ primary:1, secondary:10 },
132
+
{ primary:2, secondary:10 },
133
+
{ primary:3, secondary:10 },
118
134
],
119
135
},
120
136
],
@@ -142,142 +158,6 @@ function MyChart() {
142
158
}
143
159
```
144
160
145
-
In the following example, there is no need to use any accessors. The **default** accessors are able to easily understand this format, but **please note** that this format limits you from passing any **meta data** about your series and datums.
When data isn't in a convenient format for React Charts, **your first instinct will be to transform your data into the above formats**. Don't do that! There is an easier way 🎉 We can use the `Chart` components' **accessor props** to point things in the right direction. **Accessor props** pass the original data and the series/datums you return down the line to form a new data model. See the [`<Chart>` component](#chart) for all available accessors.
194
-
195
-
In the following example, the data is in a very funky format, but at it's core is the same as the previous examples.
Multiple series are often useless without labels. By default, React Charts looks for the `label` value on the series object you pass it. If not found, it will simply label your series as `Series [n]`, where `[n]` is the zero-based `index` of the series, plus `1`.
249
-
250
-
If the default label accessor doesn't suit your needs, then you can use the `<Chart>` component's `getLabel` accessor prop:
React Charts supports an `axes` prop that handles both the underlying scale and visual rendering. These axes can be combined and configured to plot data in many ways. To date, we have the following scale types available:
0 commit comments