Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!doctype html>
<html lang="ja">
<head>
<meta name="description" content="equation of a line">
  <meta charset="UTF-8">
  <title>Equation of a line</title>
</head>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
</body>
</html>
 
var margin = {top: 20, right: 100, bottom: 30, left: 100},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;
var xScale = d3.scale.linear()
    .domain([0, 20])
    .range([0, width]);
var yScale = d3.scale.linear()
    .domain([0, 20])
    .range([height, 0]);
var xAxis = d3.svg.axis()
    .scale(xScale)
    .orient("bottom");
var yAxis = d3.svg.axis()
    .scale(yScale)
    .orient("left");
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 + ")");
svg.append('g')
    .attr('class', 'x axis')
    .attr("transform", "translate(0," + height + ")")
    .call(xAxis);
svg.append('g')
    .attr('class', 'y axis')
    .call(yAxis);
var trianglePoints = xScale(3) + ' ' + yScale(18) + ', ' + xScale(1) + ' ' + yScale(0) + ', ' + xScale(12) + ' ' + yScale(3) + ' ' + xScale(12) + ', ' + yScale(3) + ' ' + xScale(3) + ' ' + yScale(18);
console.log(trianglePoints);
svg.append('path')
    .attr('d', function(d) { 
        var x = xScale(3), y = yScale(18);
        return 'M ' + x +' '+ y + ' l ' + xScale(10) + ' ' + yScale(10) + ' l ' + -xScale(10) + ' 0 z';
      })
    .style('stroke', 'blue');
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers