Hello,
I am evaluating vega and wanted to try out the dynamic data binding. Its been a long time since I did any javascript, so ....
I stripped my test down to use the example.
If I do this:
<html>
<head>
<title>Vega Scaffold</title>
</head>
<body>
<div id="vis"></div>
</body>
<script type="text/javascript">
// parse a spec and create a visualization view
function parse(spec) {
vg.parse.spec(spec, function(chart) { chart({el:"#vis"}).update(); });
}
parse("viz.json");
</script>
</html>
With viz.json being this:
(see attached). here is the data section.
"data": [
{
"name": "table",
"values":[
{"category":"Warner Independent", "amount":63116006},
{"category":"Buena Vista","amount":11215827077},
{"category":"Polygram","amount":16682174},
{"category":"Orion Pictures","amount":29636352},
{"category":"Freestyle","amount":32596092},
{"category":"Overture Films","amount":47580972},
{"category":"MGM","amount":579428490},
{"category":"Fine Line","amount":71784660},
{"category":"Roadside Attractions","amount":38359509},
{"category":"Dreamworks","amount":2003922292},
{"category":"Artisan","amount":30582204},
{"category":"Focus","amount":939913659}
]
}
],
It renders the bar graph as I would expect (well, it renders it, but..)
Now i change my viz.json data section to look like this:
"data": [
{
"name": "table"
}
],
now I want to bind the data when the view is constructed, so I change to this. (normally I would fetch the data from a REST call and then bind it)
<html>
<head>
<title>Vega Scaffold</title>
</head>
<body>
<div id="vis"></div>
</body>
<script type="text/javascript">
function parse(spec) {
vg.parse.spec(spec, function(chart) {
var dataJson = '{ "data": [ {' +
' "name": "table", ' +
' "values": [ ' +
' {"category":"Warner Independent", "amount":63116006}, ' +
' {"category":"Buena Vista","amount":11215827077}, ' +
' {"category":"Polygram","amount":16682174}, ' +
' {"category":"Orion Pictures","amount":29636352}, ' +
' {"category":"Freestyle","amount":32596092}, ' +
' {"category":"Overture Films","amount":47580972}, ' +
' {"category":"MGM","amount":579428490}, ' +
' {"category":"Fine Line","amount":71784660}, ' +
' {"category":"Roadside Attractions","amount":38359509}, ' +
' {"category":"Dreamworks","amount":2003922292}, ' +
' {"category":"Artisan","amount":30582204}, ' +
' {"category":"Focus","amount":939913659} ' +
' ] } ]' +
' }';
var pdata = JSON.parse(dataJson);
chart({el:"#vis", data:pdata}).update(); });
}
parse("viz_dynamic.json");
</script>
</html>
The dataJson parses fine, but when I get this error in Chrome at the highlighted line.
Uncaught TypeError: Cannot read property 'name' of undefined
i @ vega.min.js:5(anonymous function) @ vega.min.js:6o.87.g.data @ vega.min.js:6o.87.r.factory @ vega.min.js:6(anonymous function) @ vega_test.html:35(anonymous function) @ vega.min.js:7
What JSON structure does the data: expect? I have tried several variations, but no luck.
Thanks!
Steve