Last active
January 4, 2016 14:09
-
-
Save Mokhova/8632539 to your computer and use it in GitHub Desktop.
Мимидав
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> | |
<style> | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: black; | |
shape-rendering: crispEdges; | |
opacity: 0.5; | |
} | |
.axis text { | |
font-family: sans-serif; | |
font-size: 12px; | |
opacity: 0.3; | |
} | |
svg{ | |
padding: 30px; | |
} | |
</style> | |
<body> | |
<script src='http://d3js.org/d3.v3.js'></script> | |
<script src='http://d3js.org/colorbrewer.v1.js'></script> | |
<script> | |
var format = d3.time.format('%m/%d/%y'); | |
var width = 600; | |
var height = 700; | |
var x = d3.time.scale().range([0, width]); | |
var y = d3.scale.linear().range([height-150, 0]); | |
var z = d3.scale.ordinal().range(colorbrewer['RdPu'][6]); | |
var area = d3.svg.area() | |
.interpolate('cardinal') /*step*/ | |
.x(function(d) { return x(d.date) }) | |
.y0(function(d) { return y(d.y0) }) | |
.y1(function(d) { return y(d.y0 + d.y) }); | |
var svg = d3.select('body').append('svg'); | |
function prepareData(data) { | |
data.forEach(function (d) { | |
d.date = format.parse(d.date); | |
d.value = +d.value; | |
}); | |
var nest = d3.nest().key(function(d) { return d.key }); | |
var stack = d3.layout.stack() | |
.values(function(d) { return d.values }) | |
.x(function(d) { return d.date }) | |
.y(function(d) { return d.value }); | |
return stack(nest.entries(data)); | |
} | |
function prepareData(data) { | |
data.forEach(function (d) { | |
d.date = format.parse(d.date); | |
d.value = +d.value; | |
}); | |
var nest = d3.nest().key(function(d) { return d.key }); | |
var stack = d3.layout.stack() | |
.offset('silhouette') // wiggle | |
.values(function(d) { return d.values }) | |
.x(function(d) { return d.date }) | |
.y(function(d) { return d.value }); | |
return stack(nest.entries(data)); | |
} | |
d3.csv('http://nemetz.devg.ru/d3/stream.csv', function (data) { | |
var layers = prepareData(data); | |
x.domain(d3.extent(data, function (d) { return d.date })); | |
y.domain([0, d3.max(data, function (d) { return d.y0 + d.y })]); | |
svg.selectAll('.layer') | |
.data(layers) | |
.enter().append('path') | |
.on('mouseover', | |
function(d,i) {d3.select(this).attr('opacity', 0.5)} | |
) | |
.on('mouseout', | |
function(d,i) {d3.select(this).attr('opacity', 1)} | |
) | |
.attr('class', 'layer') | |
.attr('d', function (d) { return area(d.values) }) | |
.style('fill', function (d, i) { return z(i) }); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom") | |
.ticks(7) | |
svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(0," + (height-150) + ")") | |
.call(xAxis) | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient("left") | |
.ticks(7) | |
svg.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(0," + (0) + ")") | |
.call(yAxis) | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment