0.0.8 • Published 5 years ago
@ndjson-utils/vega-lite v0.0.8
@ndjson-utils/vega-lite
Create vega-lite spec from JSON or a NDJSON stream
Chart types:
- area
- bar
- line
- multiline
- pie
- scatter
Install
npm install vega-lite @ndjson-utils/vega-liteUsage
If data.json is a JSON file with an array of objects of this type:
interface Item {
label: string
value: number
}Create a bar chart:
cat data.json | bar | vl2svg > chart.svgbar creates the vega-lite spec. vl2svg comes from vega-lite and turns a spec into SVG.
bar defaults to keys being called label and value, as in our data. Otherwise, use -l and -v to define the keys (see below).
If data.ndjson is a NDJSON file where each line is an object of the type:
interface Item {
a_key: number
b_key: number
}Create a scatterplot:
cat data.ndjson | scatter -x a_key -y b_key -n true | vl2svg > chart.svgThe keys for the x and y axes are defined with -x a_key -y b_key. -n true tells scatter it receives NDJSON.
Use --help to see the expected arguments. For example:
pie --helpwill return
usage: pie [-h] [-l LABEL] [-v VALUE] [-W WIDTH] [-H HEIGHT] [-n NDJSON]
Create a bar chart from JSON or NDJSON
optional arguments:
-h, --help show this help message and exit
-l LABEL, --label LABEL
Label key (defaults to "label")
-v VALUE, --value VALUE
Value key (defaults to "value")
-W WIDTH, --width WIDTH
Chart width (defaults to "400")
-H HEIGHT, --height HEIGHT
Chart height (defaults to "200")
-n NDJSON, --ndjson NDJSON
Takes a NDJSON stream (defaults to JSON)bar
-l/--labelLabel key (defaults to "label")-v/--valueValue key (defaults to "value")-W/--widthChart width (defaults to "400")-H/--heightChart height (defaults to "200")-n/--ndjsonTakes a NDJSON stream (defaults to JSON)
scatter
-xX axis key (defaults to "x")-yY axis key (defaults to "y")-W/--widthChart width (defaults to "400")-H/--heightChart height (defaults to "400")-n/--ndjsonTakes a NDJSON stream (defaults to JSON)
line
Arguments:
-d/--dateDate key (defaults to "date")-v/--valueValue key (defaults to "value")-W/--widthChart width (defaults to "400")-H/--heightChart height (defaults to "200")-n/--ndjsonTakes a NDJSON stream (defaults to JSON)
area
-d/--dateDate key (defaults to "date")-v/--valueValue key (defaults to "value")-W/--widthChart width (defaults to "400")-H/--heightChart height (defaults to "200")-n/--ndjsonTakes a NDJSON stream (defaults to JSON)
multiline
-d/--dateDate key (defaults to "data")-v/--valuesValue keys (comma separated - required)-W/--widthChart width (defaults to "400")-H/--heightChart height (defaults to "200")-n/--ndjsonTakes a NDJSON stream (defaults to JSON)
pie
-l/--labelLabel key (defaults to "label")-v/--valueValue key (defaults to "value")-W/--widthChart width (defaults to "400")-H/--heightChart height (defaults to "200")-n/--ndjsonTakes a NDJSON stream (defaults to JSON)