Ways to hand over data
The same 2000-point series, four ways. They draw the same picture; they differ in how many bytes the page carries.
Four datasets, one result
All four charts below read a dataset of 2000 rows. Datasets that are encoded are decoded in the background; a chart shows a placeholder until its data is ready, and reports a clear error (naming the column) if the data is broken.
Rows
Columns
gzip + base64
Binary columns
| Form | Size in the page | What it is |
|---|---|---|
| Rows | 41.7 KB | An array of objects. The simplest form, and the largest. |
| Columns | 22.2 KB | One array per field: no repeated keys. |
| gzip + base64 | 13.5 KB | The JSON of rows or columns, gzipped and base64-encoded. The composer does this by itself for big datasets. Needs DecompressionStream: Chrome and Edge 80, Firefox 113, Safari 16.4. |
| Binary columns | 13.7 KB | Numeric columns as raw values, gzipped, base64: what a data pipeline can write. Integers use the smallest integer type; floats stay 64-bit, so nothing is lost. |
| Binary, v as float32 | 13.1 KB | Halves the values that are not integers, keeps about 7 digits. Only when you ask for it. |
What each one looks like
Tiny examples of the four shapes (the demo above has 2000 rows each):
Data forms
// rows
[ { "t": 0, "v": 50.2 }, { "t": 1, "v": 50.9 } ]
// columns
{ "columns": { "t": [0, 1], "v": [50.2, 50.9] } }
// gzip + base64 of the JSON above
{ "encoding": "gzip+base64", "data": "H4sIAAAAAAAA..." }
// binary columns (`scripts/encode-columns.js` writes them)
{ "columns": {
"t": { "dtype": "uint8", "encoding": "gzip+base64", "data": "H4sI..." },
"v": { "dtype": "float64", "encoding": "gzip+base64", "data": "H4sI..." }
} }
// from a CSV file, when composing a page: { "csvFile": "orders.csv" }