Chart implemented with vega.js
Last active
August 29, 2015 14:01
-
-
Save skoslitz/11544504 to your computer and use it in GitHub Desktop.
vega chart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html;charset=utf-8"> | |
| <title>Vega Live Editor</title> | |
| <script src="http://d3js.org/d3.v3.min.js">></script> | |
| <script src="http://cdnjs.cloudflare.com/ajax/libs/vega/1.4.0/vega.min.js"></script> | |
| </head> | |
| <body> | |
| <div id="growArea"</div> | |
| <script type="text/javascript"> | |
| var spec = { | |
| "width": 600, | |
| "height": 400, | |
| "padding": {"top": 100, "left": 150, "bottom": 30, "right": 10}, | |
| "data": [{"name": "table"}], | |
| "scales": [ | |
| { | |
| "name": "x", "type": "ordinal", "range": "width", | |
| "domain": {"data": "table", "field": "data.zone"} | |
| }, | |
| { | |
| "name": "y", "range": "height", "nice": true, | |
| "domain": {"data": "table", "field": "data.area"} | |
| } | |
| ], | |
| "axes": [ | |
| {"type": "x", "scale": "x"}, | |
| {"type": "y", "scale": "y"} | |
| ], | |
| "marks": [ | |
| { | |
| "type": "rect", | |
| "from": {"data": "table"}, | |
| "properties": { | |
| "enter": { | |
| "x": {"scale": "x", "field": "data.zone"}, | |
| "y": {"scale": "y", "field": "data.area"}, | |
| "y2": {"scale": "y", "value": 0}, | |
| "width": {"scale": "x", "band": true, "offset": -5} | |
| }, | |
| "update": { | |
| "fill": {"value": "green"} | |
| }, | |
| "hover": { | |
| "fill": {"value": "lightblue"} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "rect", | |
| "interactive": false, | |
| "from": {"data": "table"} | |
| } | |
| ] | |
| }; | |
| var data1 = {table: [ | |
| {"zone": 'Assam', "area": 266.512}, | |
| {"zone": 'West Bengalen', "area": 107.479}, | |
| {"zone": 'Nordindien', "area": 16.915}, | |
| {"zone": 'Tamil Nadu', "area": 74.398}, | |
| {"zone": 'Kerala', "area": 36.940}, | |
| {"zone": 'Karnataka', "area": 2.122} | |
| ]}; | |
| vg.parse.spec(spec, function(chart) { | |
| var growArea = chart({el:"#growArea", data:data1}) | |
| .update(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment