D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
adekunleoduye
Full window
Github gist
Anscombe Circle
Built with
blockbuilder.org
<!DOCTYPE html> <meta charset="utf-8"> <style type="text/css"> /*css to go here*/ .axis path { fill: none; stroke-width: 2px; stroke: black; } .axis line { stroke: black; stroke-width: 2px; stroke-opacity: 0.1; } .axis text { font: 12px sans-serif; } circle { fill: red; } </style> <body></body> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script> <script> //JS to go here var data = [ {'group':'III', 'x': 10, 'y': 7.46}, {'group':'III', 'x': 8 , 'y': 6.77}, {'group':'III', 'x': 13, 'y': 12.74}, {'group':'III', 'x': 9 , 'y': 7.11}, {'group':'III', 'x': 11, 'y': 7.81}, {'group':'III', 'x': 14, 'y': 8.84}, {'group':'III', 'x': 6 , 'y': 6.08}, {'group':'III', 'x': 4 , 'y': 5.39}, {'group':'III', 'x': 12, 'y': 8.15}, {'group':'III', 'x': 7 , 'y': 6.42}, {'group':'III', 'x': 5 , 'y': 5.73} ]; var margin = {top: 50, right: 50, bottom: 50, left: 50}; var width = 500 - margin.left - margin.right, height = 500 - margin.top - margin.bottom; var svg = 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 + ")") var xScale = d3.scale.linear() .domain([0, 15]) .range([0, width]) var yScale = d3.scale.linear() .domain([0, 15]) .range([height, 0]) var circles = svg.selectAll(".anscombe-circles") .data(data) .enter().append('circle') .attr('cx', function(d) {return xScale(d.x)}) .attr('cy', function(d) {return yScale(d.y)}) .attr('r', 5) var xAxis = d3.svg.axis() .scale(xScale) .ticks(15) .tickSize(-width) .orient("bottom"); var yAxis = d3.svg.axis() .scale(yScale) .ticks(15) .tickSize(-width) .orient("left"); svg.append("g") .attr("class", "x axis") .attr("transform","translate(0," + height + ")" ) .call(xAxis); svg.append("g") .attr("class", "y axis") .call(yAxis); // console.log(xScale.domain()); // console.log(yScale.domain()); // console.log(yScale.range()); // console.log(xScale.range()); </script>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js