使用D3.js画心形图


<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>d3 testtitle>
    <script type="text/javascript" src="d3.js">script>
head>
<body>
    <svg>svg>
body>
<script type="text/javascript">
    let data=[];
    let a=20;
    for(let t=0;t<1000;t++){
        let x=a*(2*Math.cos(t)-Math.cos(2*t));
        let y=a*(2*Math.sin(t)-Math.sin(2*t));
        data.push({x:x+100,y:y+100});
    }
    let svg=d3.select("body").append('svg').attr("width",500).attr("height",500).attr("transform","rotate(7deg)");
    let line=d3.line().x(function(d,i) {return d.x}).y(function(d) {return d.y;});
    let path=svg.append("path");
    path.attr("d",line(data)).attr("stroke","#000000").attr("stroke-width","2px");
script>
html>

你可能感兴趣的:(前端)