Skip to content

Instantly share code, notes, and snippets.

@NPashaP
Created December 15, 2016 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NPashaP/4b64f2311e071b1f1e6120f01b6e4319 to your computer and use it in GitHub Desktop.
Save NPashaP/4b64f2311e071b1f1e6120f01b6e4319 to your computer and use it in GitHub Desktop.
bar - fill by value
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
rect{
}
</style>
<body>
<svg width="960" height="600"></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', 1],['A', 3],['B', 3],['C', -3],['D', 8]];
var bar=viz.bar().data(data)
.fill(function(d){ return d.value < 0 ? '#FF7043': '#42A5F5';});
var svg = d3.select("svg")
.append("g")
.attr("transform","translate(50,50)")
.call(bar);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment