Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <style>
- body {
- font: 10px sans-serif;
- }
- .axis path,
- .axis line {
- fill: none;
- stroke: #000;
- shape-rendering: crispEdges;
- }
- .x.axis path {
- display: none;
- }
- .area.above {
- fill: rgb(252,141,89);
- }
- .area.below {
- fill: rgb(145,207,96);
- }
- .line {
- fill: none;
- stroke: #000;
- stroke-width: 1.5px;
- }
- </style>
- <body>
- <script src="d3.v3.min.js"></script>
- <script>
- var format = d3.time.format("%Y-%m-%d");
- var margin = {top: 20, right: 20, bottom: 30, left: 50},
- width = 960 - margin.left - margin.right,
- height = 500 - margin.top - margin.bottom;
- var xstream = d3.time.scale()
- .range([0, width]);
- var ystream = d3.scale.linear()
- .range([height, 0]);
- var xAxisstream = d3.svg.axis()
- .scale(xstream)
- .orient("bottom");
- var yAxisstream = d3.svg.axis()
- .scale(ystream)
- .orient("left");
- var linestream = d3.svg.area()
- .interpolate("basis")
- .x(function(dstream) { return xstream(dstream["unixtime"]); })
- .y(function(dstream) { return ystream(dstream["stream"]); });
- var areastream = d3.svg.area()
- .interpolate("basis")
- .x(function(dstream) { return xstream(dstream["unixtime"]); })
- .y1(function(dstream) { return ystream(dstream["stream"]); });
- var svgstream = d3.select("body").append("svg")
- .attr("width", width + margin.left + margin.right)
- .attr("height", height + margin.top + margin.bottom)
- .append("g")
- .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
- d3.csv("streamvalues.csv", function(errorstream, datastream) {
- datastream.forEach(function(dstream) {
- dstream["unixtime"] = format(new Date(dstream["unixtime"]));
- dstream["stream"]= +dstream["stream"];
- dstream["stream-7.5%"]= +dstream["stream"] * .925;
- dstream["stream+7.5%"]= +dstream["stream"] * .1075;
- });
- xstream.domain(d3.extent(datastream, function(dstream) { return dstream["unixtime"] }));
- ystream.domain([
- d3.min(datastream, function(dstream) { return dstream["stream-7.5%"] }),
- d3.max(datastream, function(dstream) { return dstream["stream+7.5%"] }),
- ]);
- svgstream.datum(datastream);
- svgstream.append("clipPath")
- .attr("id", "clip-below")
- .append("path")
- .attr("dstream", areastream.y0(height));
- svgstream.append("clipPath")
- .attr("id", "clip-above")
- .append("path")
- .attr("dstream", areastream.y0(0));
- svgstream.append("path")
- .attr("class", "area above")
- .attr("clip-path", "url(#clip-above)")
- .attr("dstream", areastream.y0(function(dstream) { return ystream(dstream["stream-7.5%"]); }));
- svgstream.append("path")
- .attr("class", "area below")
- .attr("clip-path", "url(#clip-below)")
- .attr("dstream", areastream);
- svgstream.append("path")
- .attr("class", "line")
- .attr("dstream", linestream);
- svgstream.append("g")
- .attr("class", "x axis")
- .attr("transform", "translate(0," + height + ")")
- .call(xAxisstream);
- svgstream.append("g")
- .attr("class", "y axis")
- .call(yAxisstream)
- .append("text")
- .attr("transform", "rotate(-90)")
- .attr("ystream", 6)
- .attr("dystream", ".71em")
- .style("text-anchor", "end")
- .text("Mbps");
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement