Last active
December 15, 2016 20:23
-
-
Save NPashaP/c2ee8555d56e08d0e7e4c8fbca025875 to your computer and use it in GitHub Desktop.
bar- fill by Primary key
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
license: gpl-3.0 |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
rect{ | |
fill:#42A5F5; | |
stroke:black; | |
} | |
</style> | |
<body> | |
<svg width="960" height="500"> | |
<g id="default" transform="translate(40, 50)"></g> | |
<g id="custom" transform="translate(520, 50)"></g> | |
</svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="http://vizjs.org/viz.v1.1.7.min.js"></script> | |
<script> | |
var data=[['A', 3, 'x'],['A', 5, 'y'],['B', 2, 'x'],['C', 2, 'x'],['C', -4, 'y'],['D', 3, 'y']]; | |
//default | |
var bardef = viz.bar().data(data); | |
d3.select("#default").call(bardef); | |
//custom | |
var color ={'A':'#EAC124','B':'#739211', 'C':'#D92405', 'D':'#3563EB' }; | |
var barcust = viz.bar().data(data) | |
.fill(function(d){ return color[d.primaryKey];}); | |
d3.select("#custom").call(barcust); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment