Simple gauge visualization example for Vega 1.5
Created
August 27, 2015 02:26
-
-
Save anilkpatro/0cf0503b581556a14aab to your computer and use it in GitHub Desktop.
Gauge Visualization with Vega
This file contains 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
<html> | |
<head> | |
<title>Vega Gauge Visualization</title> | |
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script> | |
<script type="text/javascript" src="https://rawgithub.com/anilkpatro/vega/master/vega.min.js"></script> | |
<style> | |
* { font-family: Helvetica Neue, Arial, sans-serif; font-size: 16px; } | |
body { | |
width: 560px; | |
margin: 10px auto; | |
} | |
</style> | |
</head> | |
<body> | |
<p><strong>Vega Gauge Visualization</strong></p> | |
<div id="view" class="view"></div> | |
</body> | |
<script type="text/javascript"> | |
var spec = | |
{ | |
"name": "gauge", | |
"width": 400, | |
"height": 400, | |
"data": [ | |
{ | |
"name": "table", | |
"values": [ | |
23 | |
] | |
} | |
], | |
"scales": [ | |
{ | |
"name": "s", | |
"type": "linear", | |
"domainMin": 0, | |
"domainMax": 100, | |
"rangeMin": -2.3561, | |
"rangeMax": 2.3561, | |
"clamp": "true" | |
} | |
], | |
"marks": [ | |
{ | |
"type": "arc", | |
"properties": { | |
"enter": { | |
"x": { | |
"group": "width", | |
"mult": 0.5 | |
}, | |
"y": { | |
"group": "height", | |
"mult": 0.5 | |
}, | |
"startAngle": { | |
"value": -2.3562 | |
}, | |
"endAngle": { | |
"value": 2.3562 | |
}, | |
"innerRadius": { | |
"value": 50 | |
}, | |
"outerRadius": { | |
"value": 80 | |
}, | |
"fill": { | |
"value": "#eee" | |
}, | |
"stroke": { | |
"value": "#000" | |
} | |
} | |
} | |
}, | |
{ | |
"type": "arc", | |
"from": { | |
"data": "table" | |
}, | |
"properties": { | |
"enter": { | |
"x": { | |
"group": "width", | |
"mult": 0.5 | |
}, | |
"y": { | |
"group": "height", | |
"mult": 0.5 | |
}, | |
"startAngle": { | |
"field": "data", | |
"scale": "s" | |
}, | |
"endAngle": { | |
"field": "data", | |
"scale": "s" | |
}, | |
"innerRadius": { | |
"value": 0 | |
}, | |
"outerRadius": { | |
"value": 85 | |
}, | |
"fill": { | |
"value": "#000" | |
}, | |
"strokeWidth": { | |
"value": 4 | |
}, | |
"stroke": { | |
"value": "#000" | |
} | |
} | |
} | |
}, | |
{ | |
"type": "text", | |
"from": { | |
"data": "table" | |
}, | |
"name": "value", | |
"properties": { | |
"enter": { | |
"align": { | |
"value": "center" | |
}, | |
"baseline": { | |
"value": "middle" | |
}, | |
"fill": { | |
"value": "#000" | |
}, | |
"font": { | |
"value": "Helvetica Neue" | |
}, | |
"fontSize": { | |
"value": 18 | |
}, | |
"text": { | |
"template": "{{data|number:'.2r'}}" | |
}, | |
"x": { | |
"group": "width", | |
"mult": 0.5 | |
}, | |
"y": { | |
"group": "height", | |
"mult": 0.5 | |
}, | |
"dy": { | |
"value": 50 | |
} | |
} | |
} | |
} | |
] | |
}; | |
vg.parse.spec(spec, function(chart) { | |
var view = chart({el:"#view"}) | |
.update(); | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment