'How can we proramatically generate vega grammar JSON from vega-lite plot?
I am able to get vega json grammar on local installation of nodejs with vega-lite and vega-lite-api installed through npm as follows:
vl = require('vega-lite')
vla = require('vega-lite-api')
data = require('vega-datasets')
const df2 = data['movies.json']()
const plot = vla.markBar().data(df2).encode(
vla.x().fieldQ('IMDB_Rating').bin(true),
vla.y().count()
)
vega_lite_json = plot.toObject();
vega_json = vl.compile(plot.toObject()).spec;
However I am unable to make it work in Observablehq.
I am not able to do last line: vl.compile(...).
This is what I have did:
vegalite = require("@observablehq/[email protected]")
vegalite.compile(plot.toObject()).spec;
It says: TypeError: vegalite.compile is not a function
Here is link to my observablehq notebook cell executing vegalie.compile(...).
What I am doing wrong?
Solution 1:[1]
the vegalite compile option is located within the vl object, like this: vl.vegalite.compile(...)
Here's a notebook with the modified code: https://observablehq.com/@shan/untitled/6
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shan Carter |
