Last active
June 15, 2018 20:30
-
-
Save Mbrownshoes/473f153bb8e97062f0f4696aebe7a22c to your computer and use it in GitHub Desktop.
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> | |
| <svg width="960" height="500"></svg> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <script> | |
| var svg = d3.select("svg"), | |
| margin = {top: 20, right: 20, bottom: 30, left: 50}, | |
| width = +svg.attr("width") - margin.left - margin.right, | |
| height = +svg.attr("height") - margin.top - margin.bottom, | |
| g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
| var IsoParse = d3.utcParse("%Y-%m-%dT%H:%M:%S%Z"); | |
| var x = d3.scaleTime() | |
| .rangeRound([0, width]); | |
| var y = d3.scaleLinear() | |
| .rangeRound([height, 0]); | |
| var line = d3.line() | |
| .x(function(d) { return x(d.date); }) | |
| .y(function(d) { return y(d.close); }); | |
| d3.json("https://erddap.aoos.org/erddap/tabledap/org_hakai_quadra.json?time%2Clatitude%2Clongitude%2Cstation%2CpCO2%2Comega_aragonite%2Csea_water_temperature%2Cdissolved_carbon_dioxide_co2%2Csea_water_practical_salinity%2Csea_water_ph_reported_on_total_scale%2Csea_water_alkalinity_expressed_as_mole_equivalent%2Cdepth&time%3E=2018-06-08T00%3A00%3A00Z&time%3C=2018-06-15T14%3A24%3A07Z", function(d) { | |
| dat = d.table.rows | |
| console.log(IsoParse(dat[1][0])) | |
| d.date = IsoParse(d.date); | |
| d.close = +d.close; | |
| return d; | |
| }, function(error, data) { | |
| console.log(data) | |
| if (error) throw error; | |
| x.domain(d3.extent(data, function(d) { return d.date; })); | |
| y.domain(d3.extent(data, function(d) { return d.close; })); | |
| g.append("g") | |
| .attr("transform", "translate(0," + height + ")") | |
| .call(d3.axisBottom(x)) | |
| .select(".domain") | |
| .remove(); | |
| g.append("g") | |
| .call(d3.axisLeft(y)) | |
| .append("text") | |
| .attr("fill", "#000") | |
| .attr("transform", "rotate(-90)") | |
| .attr("y", 6) | |
| .attr("dy", "0.71em") | |
| .attr("text-anchor", "end") | |
| .text("Price ($)"); | |
| g.append("path") | |
| .datum(data) | |
| .attr("fill", "none") | |
| .attr("stroke", "steelblue") | |
| .attr("stroke-linejoin", "round") | |
| .attr("stroke-linecap", "round") | |
| .attr("stroke-width", 1.5) | |
| .attr("d", line); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment