Built with blockbuilder.org
Last active
January 3, 2017 11:02
-
-
Save hashimkey/010c50a51069af07fb17ff8ac87feec9 to your computer and use it in GitHub Desktop.
let us how it goes
This file contains hidden or 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: mit |
This file contains hidden or 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> | |
| svg { | |
| font: 10px sans-serif; | |
| } | |
| .axis path, | |
| .axis line { | |
| fill: none; | |
| stroke: #000; | |
| shape-rendering: crispEdges; | |
| } | |
| .y.axis path { | |
| fill: none; | |
| stroke: #000; | |
| shape-rendering: crispEdges; | |
| } | |
| .brush .extent { | |
| stroke: #fff; | |
| fill-opacity: .125; | |
| shape-rendering: crispEdges; | |
| } | |
| .line { | |
| fill: none; | |
| } | |
| </style> | |
| <body> | |
| <script src="http://d3js.org/d3.v3.min.js"></script> | |
| <script> | |
| var margin = {top: 10, right: 10, bottom: 100, left: 40}, | |
| margin2 = {top: 430, right: 10, bottom: 20, left: 40}, | |
| width = 960 - margin.left - margin.right, | |
| height = 500 - margin.top - margin.bottom, | |
| height2 = 500 - margin2.top - margin2.bottom; | |
| var color = d3.scale.category10(); | |
| var parseDate = d3.time.format("%Y%m").parse; | |
| var x = d3.time.scale().range([0, width]), | |
| x2 = d3.time.scale().range([0, width]), | |
| y = d3.scale.linear().range([height, 0]), | |
| y2 = d3.scale.linear().range([height2, 0]); | |
| var xAxis = d3.svg.axis().scale(x).orient("bottom"), | |
| xAxis2 = d3.svg.axis().scale(x2).orient("bottom"), | |
| yAxis = d3.svg.axis().scale(y).orient("left"); | |
| var brush = d3.svg.brush() | |
| .x(x2) | |
| .on("brush", brush); | |
| var line = d3.svg.line() | |
| .defined(function(d) { return !isNaN(d.temperature); }) | |
| .interpolate("cubic") | |
| .x(function(d) { return x(d.date); }) | |
| .y(function(d) { return y(d.temperature); }); | |
| var line2 = d3.svg.line() | |
| .defined(function(d) { return !isNaN(d.temperature); }) | |
| .interpolate("cubic") | |
| .x(function(d) {return x2(d.date); }) | |
| .y(function(d) {return y2(d.temperature); }); | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width + margin.left + margin.right) | |
| .attr("height", height + margin.top + margin.bottom); | |
| svg.append("defs").append("clipPath") | |
| .attr("id", "clip") | |
| .append("rect") | |
| .attr("width", width) | |
| .attr("height", height); | |
| var focus = svg.append("g") | |
| .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
| var context = svg.append("g") | |
| .attr("transform", "translate(" + margin2.left + "," + margin2.top + ")"); | |
| d3.csv("test.csv", function(error, data) { | |
| color.domain(d3.keys(data[0]).filter(function(key) { return key !== "date"; })); | |
| data.forEach(function(d) { | |
| d.date = parseDate(d.date); | |
| }); | |
| var sources = color.domain().map(function(name) { | |
| return { | |
| name: name, | |
| values: data.map(function(d) { | |
| return {date: d.date, temperature: +d[name]}; | |
| }) | |
| }; | |
| }); | |
| x.domain(d3.extent(data, function(d) { return d.date; })); | |
| y.domain([d3.min(sources, function(c) { return d3.min(c.values, function(v) { return v.temperature; }); }), | |
| d3.max(sources, function(c) { return d3.max(c.values, function(v) { return v.temperature; }); }) ]); | |
| x2.domain(x.domain()); | |
| y2.domain(y.domain()); | |
| var focuslineGroups = focus.selectAll("g") | |
| .data(sources) | |
| .enter().append("g"); | |
| var focuslines = focuslineGroups.append("path") | |
| .attr("class","line") | |
| .attr("d", function(d) { return line(d.values); }) | |
| .style("stroke", function(d) {return color(d.name);}) | |
| .attr("clip-path", "url(#clip)"); | |
| focus.append("g") | |
| .attr("class", "x axis") | |
| .attr("transform", "translate(0," + height + ")") | |
| .call(xAxis); | |
| focus.append("g") | |
| .attr("class", "y axis") | |
| .call(yAxis); | |
| var contextlineGroups = context.selectAll("g") | |
| .data(sources) | |
| .enter().append("g"); | |
| var contextLines = contextlineGroups.append("path") | |
| .attr("class", "line") | |
| .attr("d", function(d) { return line2(d.values); }) | |
| .style("stroke", function(d) {return color(d.name);}) | |
| .attr("clip-path", "url(#clip)"); | |
| context.append("g") | |
| .attr("class", "x axis") | |
| .attr("transform", "translate(0," + height2 + ")") | |
| .call(xAxis2); | |
| context.append("g") | |
| .attr("class", "x brush") | |
| .call(brush) | |
| .selectAll("rect") | |
| .attr("y", -6) | |
| .attr("height", height2 + 7); | |
| }); | |
| function brush() { | |
| x.domain(brush.empty() ? x2.domain() : brush.extent()); | |
| focus.selectAll("path.line").attr("d", function(d) {return line(d.values)}); | |
| focus.select(".x.axis").call(xAxis); | |
| focus.select(".y.axis").call(yAxis); | |
| } | |
| </script> |
This file contains hidden or 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
| date | value | |
|---|---|---|
| 1-Nov-14 | 0 | |
| 8-Nov-14 | 0 | |
| 9-Nov-14 | 0 | |
| 10-Nov-14 | 0 | |
| 11-Nov-14 | 0 | |
| 12-Nov-14 | 0 | |
| 13-Nov-14 | 0 | |
| 14-Nov-14 | 0 | |
| 15-Nov-14 | 0 | |
| 16-Nov-14 | 0 | |
| 17-Nov-14 | 0 | |
| 18-Nov-14 | 0 | |
| 19-Nov-14 | 0 | |
| 20-Nov-14 | 0 | |
| 21-Nov-14 | 0 | |
| 22-Nov-14 | 0 | |
| 23-Nov-14 | 0 | |
| 24-Nov-14 | 0 | |
| 25-Nov-14 | 0 | |
| 26-Nov-14 | 0 | |
| 27-Nov-14 | 0 | |
| 28-Nov-14 | 0 | |
| 29-Nov-14 | 0 | |
| 30-Nov-14 | 0 | |
| 1-Dec-14 | 0 | |
| 2-Dec-14 | 0 | |
| 3-Dec-14 | 0 | |
| 4-Dec-14 | 0 | |
| 5-Dec-14 | 0 | |
| 6-Dec-14 | 0 | |
| 7-Dec-14 | 0 | |
| 8-Dec-14 | 0 | |
| 9-Dec-14 | 0 | |
| 10-Dec-14 | 0 | |
| 11-Dec-14 | 0 | |
| 12-Dec-14 | 0 | |
| 13-Dec-14 | 0 | |
| 14-Dec-14 | 0 | |
| 15-Dec-14 | 0 | |
| 16-Dec-14 | 0 | |
| 17-Dec-14 | 0 | |
| 18-Dec-14 | 0 | |
| 19-Dec-14 | 0 | |
| 20-Dec-14 | 0 | |
| 21-Dec-14 | 0 | |
| 22-Dec-14 | 0 | |
| 23-Dec-14 | 0 | |
| 24-Dec-14 | 0 | |
| 25-Dec-14 | 0 | |
| 26-Dec-14 | 0 | |
| 27-Dec-14 | 0 | |
| 28-Dec-14 | 0 | |
| 29-Dec-14 | 0 | |
| 30-Dec-14 | 0 | |
| 31-Dec-14 | 0 | |
| 1-Jan-15 | 0 | |
| 2-Jan-15 | 0 | |
| 3-Jan-15 | 0 | |
| 4-Jan-15 | 0 | |
| 5-Jan-15 | 0 | |
| 6-Jan-15 | 0 | |
| 7-Jan-15 | 0 | |
| 8-Jan-15 | 0 | |
| 9-Jan-15 | 0 | |
| 10-Jan-15 | 0 | |
| 11-Jan-15 | 0 | |
| 12-Jan-15 | 0 | |
| 13-Jan-15 | 0 | |
| 14-Jan-15 | 0 | |
| 15-Jan-15 | 0 | |
| 16-Jan-15 | 0 | |
| 17-Jan-15 | 0 | |
| 18-Jan-15 | 0 | |
| 19-Jan-15 | 0 | |
| 20-Jan-15 | 0 | |
| 21-Jan-15 | 0 | |
| 22-Jan-15 | 0 | |
| 23-Jan-15 | 0 | |
| 24-Jan-15 | 0 | |
| 25-Jan-15 | 0 | |
| 26-Jan-15 | 0 | |
| 27-Jan-15 | 0 | |
| 28-Jan-15 | 0 | |
| 29-Jan-15 | 0 | |
| 30-Jan-15 | 0 | |
| 31-Jan-15 | 0 | |
| 1-Feb-15 | 0 | |
| 2-Feb-15 | 0 | |
| 3-Feb-15 | 0 | |
| 4-Feb-15 | 0 | |
| 5-Feb-15 | 0 | |
| 6-Feb-15 | 0 | |
| 7-Feb-15 | 0 | |
| 8-Feb-15 | 0 | |
| 9-Feb-15 | 0 | |
| 10-Feb-15 | 0 | |
| 11-Feb-15 | 0 | |
| 12-Feb-15 | 0 | |
| 13-Feb-15 | 0 | |
| 14-Feb-15 | 0 | |
| 15-Feb-15 | 0 | |
| 16-Feb-15 | 0 | |
| 17-Feb-15 | 0 | |
| 18-Feb-15 | 0 | |
| 19-Feb-15 | 0 | |
| 20-Feb-15 | 0 | |
| 21-Feb-15 | 0 | |
| 22-Feb-15 | 0 | |
| 23-Feb-15 | 0 | |
| 24-Feb-15 | 0 | |
| 25-Feb-15 | 0 | |
| 26-Feb-15 | 0 | |
| 27-Feb-15 | 0 | |
| 28-Feb-15 | 0 | |
| 1-Mar-15 | 0 | |
| 2-Mar-15 | 0 | |
| 3-Mar-15 | 0 | |
| 4-Mar-15 | 432333.3333 | |
| 5-Mar-15 | 384833.3333 | |
| 6-Mar-15 | 409833.3333 | |
| 7-Mar-15 | 410583.3333 | |
| 8-Mar-15 | 396500 | |
| 9-Mar-15 | 408000 | |
| 10-Mar-15 | 458916.6667 | |
| 11-Mar-15 | 405916.6667 | |
| 12-Mar-15 | 258166.6667 | |
| 13-Mar-15 | 0 | |
| 14-Mar-15 | 0 | |
| 15-Mar-15 | 0 | |
| 16-Mar-15 | 0 | |
| 17-Mar-15 | 0 | |
| 18-Mar-15 | 6416.666667 | |
| 19-Mar-15 | 303666.6667 | |
| 20-Mar-15 | 403333.3333 | |
| 21-Mar-15 | 402833.3333 | |
| 22-Mar-15 | 452250 | |
| 23-Mar-15 | 427083.3333 | |
| 24-Mar-15 | 471833.3333 | |
| 25-Mar-15 | 403583.3333 | |
| 26-Mar-15 | 419083.3333 | |
| 27-Mar-15 | 447500 | |
| 28-Mar-15 | 511333.3333 | |
| 29-Mar-15 | 440250 | |
| 30-Mar-15 | 390333.3333 | |
| 31-Mar-15 | 352666.6667 | |
| 1-Apr-15 | 182333.3333 | |
| 2-Apr-15 | 367166.6667 | |
| 3-Apr-15 | 359083.3333 | |
| 4-Apr-15 | 383750 | |
| 5-Apr-15 | 473166.6667 | |
| 6-Apr-15 | 416333.3333 | |
| 7-Apr-15 | 480416.6667 | |
| 8-Apr-15 | 420750 | |
| 9-Apr-15 | 486333.3333 | |
| 10-Apr-15 | 461666.6667 | |
| 11-Apr-15 | 512416.6667 | |
| 12-Apr-15 | 419500 | |
| 13-Apr-15 | 423916.6667 | |
| 14-Apr-15 | 413000 | |
| 15-Apr-15 | 529000 | |
| 16-Apr-15 | 512166.6667 | |
| 17-Apr-15 | 539500 | |
| 18-Apr-15 | 493166.6667 | |
| 19-Apr-15 | 554416.6667 | |
| 20-Apr-15 | 500083.3333 | |
| 21-Apr-15 | 542583.3333 | |
| 22-Apr-15 | 477250 | |
| 23-Apr-15 | 473333.3333 | |
| 24-Apr-15 | 435750 | |
| 25-Apr-15 | 483333.3333 | |
| 26-Apr-15 | 376000 | |
| 27-Apr-15 | 422916.6667 | |
| 28-Apr-15 | 144666.6667 | |
| 29-Apr-15 | 184500 | |
| 30-Apr-15 | 394000 | |
| 1-May-15 | 452833.3333 | |
| 2-May-15 | 499166.6667 | |
| 3-May-15 | 481916.6667 | |
| 4-May-15 | 452833.3333 | |
| 5-May-15 | 501666.6667 | |
| 6-May-15 | 539666.6667 | |
| 7-May-15 | 574333.3333 | |
| 8-May-15 | 489416.6667 | |
| 9-May-15 | 396250 | |
| 10-May-15 | 497166.6667 | |
| 11-May-15 | 500250 | |
| 12-May-15 | 470250 | |
| 13-May-15 | 541083.3333 | |
| 14-May-15 | 528000 | |
| 15-May-15 | 526916.6667 | |
| 16-May-15 | 480916.6667 | |
| 17-May-15 | 525333.3333 | |
| 18-May-15 | 548333.3333 | |
| 19-May-15 | 588500 | |
| 20-May-15 | 566916.6667 | |
| 21-May-15 | 574333.3333 | |
| 22-May-15 | 574666.6667 | |
| 23-May-15 | 568250 | |
| 24-May-15 | 491583.3333 | |
| 25-May-15 | 568083.3333 | |
| 26-May-15 | 441666.6667 | |
| 27-May-15 | 533333.3333 | |
| 28-May-15 | 547000 | |
| 29-May-15 | 549916.6667 | |
| 30-May-15 | 574083.3333 | |
| 31-May-15 | 588666.6667 | |
| 1-Jun-15 | 587000 | |
| 2-Jun-15 | 566750 | |
| 3-Jun-15 | 565750 | |
| 4-Jun-15 | 221916.6667 | |
| 5-Jun-15 | 0 | |
| 6-Jun-15 | 0 | |
| 7-Jun-15 | 0 | |
| 8-Jun-15 | 0 | |
| 9-Jun-15 | 0 | |
| 10-Jun-15 | 2083.333333 | |
| 11-Jun-15 | 104000 | |
| 12-Jun-15 | 418416.6667 | |
| 13-Jun-15 | 458666.6667 | |
| 14-Jun-15 | 537333.3333 | |
| 15-Jun-15 | 551833.3333 | |
| 16-Jun-15 | 549833.3333 | |
| 17-Jun-15 | 534000 | |
| 18-Jun-15 | 532000 | |
| 19-Jun-15 | 511666.6667 | |
| 20-Jun-15 | 516916.6667 | |
| 21-Jun-15 | 502833.3333 | |
| 22-Jun-15 | 497916.6667 | |
| 23-Jun-15 | 476750 | |
| 24-Jun-15 | 485833.3333 | |
| 25-Jun-15 | 511166.6667 | |
| 26-Jun-15 | 530250 | |
| 27-Jun-15 | 523083.3333 | |
| 28-Jun-15 | 523083.3333 | |
| 29-Jun-15 | 505083.3333 | |
| 30-Jun-15 | 515250 | |
| 1-Jul-15 | 516833.3333 | |
| 2-Jul-15 | 513416.6667 | |
| 3-Jul-15 | 507166.6667 | |
| 4-Jul-15 | 495916.6667 | |
| 5-Jul-15 | 503166.6667 | |
| 6-Jul-15 | 488083.3333 | |
| 7-Jul-15 | 463416.6667 | |
| 8-Jul-15 | 458416.6667 | |
| 9-Jul-15 | 489000 | |
| 10-Jul-15 | 523416.6667 | |
| 11-Jul-15 | 494000 | |
| 12-Jul-15 | 512250 | |
| 13-Jul-15 | 489666.6667 | |
| 14-Jul-15 | 480666.6667 | |
| 15-Jul-15 | 491500 | |
| 16-Jul-15 | 502416.6667 | |
| 17-Jul-15 | 498000 | |
| 18-Jul-15 | 526083.3333 | |
| 19-Jul-15 | 521583.3333 | |
| 20-Jul-15 | 515166.6667 | |
| 21-Jul-15 | 500333.3333 | |
| 22-Jul-15 | 527333.3333 | |
| 23-Jul-15 | 524416.6667 | |
| 24-Jul-15 | 548000 | |
| 25-Jul-15 | 524500 | |
| 26-Jul-15 | 538166.6667 | |
| 27-Jul-15 | 492666.6667 | |
| 28-Jul-15 | 537583.3333 | |
| 29-Jul-15 | 470750 | |
| 30-Jul-15 | 514333.3333 | |
| 31-Jul-15 | 501500 | |
| 1-Aug-15 | 532583.3333 | |
| 2-Aug-15 | 479500 | |
| 3-Aug-15 | 516833.3333 | |
| 4-Aug-15 | 470416.6667 | |
| 5-Aug-15 | 488416.6667 | |
| 6-Aug-15 | 499583.3333 | |
| 7-Aug-15 | 491000 | |
| 8-Aug-15 | 500333.3333 | |
| 9-Aug-15 | 513833.3333 | |
| 10-Aug-15 | 493500 | |
| 11-Aug-15 | 521666.6667 | |
| 12-Aug-15 | 484666.6667 | |
| 13-Aug-15 | 505333.3333 | |
| 14-Aug-15 | 472333.3333 | |
| 15-Aug-15 | 505000 | |
| 16-Aug-15 | 503333.3333 | |
| 17-Aug-15 | 494333.3333 | |
| 18-Aug-15 | 456666.6667 | |
| 19-Aug-15 | 494166.6667 | |
| 20-Aug-15 | 500166.6667 | |
| 21-Aug-15 | 509583.3333 | |
| 22-Aug-15 | 480083.3333 | |
| 23-Aug-15 | 521250 | |
| 24-Aug-15 | 496833.3333 | |
| 25-Aug-15 | 484750 | |
| 26-Aug-15 | 409250 | |
| 27-Aug-15 | 428166.6667 | |
| 28-Aug-15 | 537666.6667 | |
| 29-Aug-15 | 557333.3333 | |
| 30-Aug-15 | 461083.3333 | |
| 31-Aug-15 | 534000 | |
| 1-Sep-15 | 308416.6667 | |
| 2-Sep-15 | 393416.6667 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment