Last active
December 15, 2016 20:23
-
-
Save NPashaP/4bd7aed5e17dd5d4d29494135970876a to your computer and use it in GitHub Desktop.
Add Value axis
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; | |
} | |
line, path{ | |
stroke-opacity:0.5; | |
shape-rendering:crispEdges; | |
} | |
.tick{ | |
stroke-dasharray:2; | |
} | |
</style> | |
<body> | |
<svg width="960" height="600"> | |
<g id="left" transform="translate(115, 25)"></g> | |
<g id="right" transform="translate(595, 25)"></g> | |
<g id="top" transform="translate(115, 325)"></g> | |
<g id="bottom" transform="translate(595, 325)"></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', 1],['A', 3],['B', 3],['C', -5],['D', 8]]; | |
//dock left | |
var barLeft = viz.bar().data(data).width(250).height(250).dock('l'); | |
d3.select("#left") | |
.append("g").attr("transform", "translate(0,0)") | |
.call(d3.axisTop().scale(barLeft.valueScale()).tickSize(-250).tickSizeOuter(0)); | |
d3.select("#left").call(barLeft); | |
//dock right | |
var barRight = viz.bar().data(data).width(250).height(250).dock('r'); | |
d3.select("#right") | |
.append("g").attr("transform", "translate(0,0)") | |
.call(d3.axisTop().scale(barRight.valueScale()).tickSize(-250).tickSizeOuter(0)); | |
d3.select("#right").call(barRight); | |
//dock top | |
var barTop = viz.bar().data(data).width(250).height(250).dock('t'); | |
d3.select("#top") | |
.append("g").attr("transform", "translate(0,0)") | |
.call(d3.axisLeft().scale(barTop.valueScale()).tickSize(-250).tickSizeOuter(0)); | |
d3.select("#top").call(barTop); | |
//dock bottom | |
var barBottom = viz.bar().data(data).width(250).height(250).dock('b'); | |
d3.select("#bottom") | |
.append("g").attr("transform", "translate(0,0)") | |
.call(d3.axisLeft().scale(barBottom.valueScale()).tickSize(-250).tickSizeOuter(0)); | |
d3.select("#bottom").call(barBottom); | |
// adjust the bl.ocks frame dimension. | |
d3.select(self.frameElement).style("height","600px").style("width","960px"); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment