初次接触d3.js,能感觉到它的强大,想要完全搞懂还是要花一番功夫,最近用它画了个折线图作为入门,以后还要多学习,请大家指教。
这个例子是在网上找到的,然后自己看懂这些代码的意思,小调整了一下,作为笔记出现,方便下次参考。
首先看一下效果图:
![3872133-42b5e9e30ad16ed5.png](https://i-blog.csdnimg.cn/blog_migrate/17e71d13c71903fd50f9c744f93f8f8e.webp?x-image-process=image/format,png)
image.png
以下为源代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>d3折线图</title>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="d3.v3.min.js"></script>
<style>
body {
font: 10px sans-serif;
margin: 50px;
}
.grid .tick {
stroke: lightgrey;
opacity: 0.7;
shape-rendering: crispEdges;
}
.grid path {
stroke-width: 0;
}
.axis path {
fill: none;
stroke: #bbb;
shape-rendering: crispEdges;
}
.axis text {
fill: #555;
}
.axis line {
stroke: #e7e7e7;
shape-rendering: crispEdges;
}
.axis .axis-label {
font-size: 14px;
}