Built with blockbuilder.org
forked from 00Deez's block: fresh block
| license: mit |
Built with blockbuilder.org
forked from 00Deez's block: fresh block
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="http://d3js.org/d3.v4.min.js"></script> | |
| <style> | |
| body { position:fixed;top:0;right:0;bottom:0;left:0; } | |
| </style> | |
| </head> | |
| <body> | |
| <h2>Scatter Plot</h2> | |
| <script> | |
| // Chart Properties | |
| var margin = {top: 20, right: 55, bottom: 50, left: 70}; | |
| var width = 960 - margin.left - margin.right; | |
| var height = 500 - margin.top - margin.bottom; | |
| // setup x | |
| var xValue = function(d) { return d.Calories;}, // data -> value | |
| xScale = d3.scale.linear().range([0, width]), // value -> display | |
| xMap = function(d) { return xScale(xValue(d));}, // data -> display | |
| xAxis = d3.svg.axis().scale(xScale).orient("bottom"); | |
| // setup y | |
| var yValue = function(d) { return d["Protein (g)"];}, // data -> value | |
| yScale = d3.scale.linear().range([height, 0]), // value -> display | |
| yMap = function(d) { return yScale(yValue(d));}, // data -> display | |
| yAxis = d3.svg.axis().scale(yScale).orient("left"); | |
| var svg = d3.select("body").append("svg") | |
| .attr("width", width) | |
| .attr("height", height); | |
| // x-axis | |
| svg.append("g") | |
| .attr("class", "axis x-axis") | |
| .attr("transform", "translate(0," + height + ")") // move axis to bottom of chart | |
| .call(d3.axisBottom(xScale)); | |
| </script> | |
| </body> |