效果图
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>d3 tree</title>
<style type="text/css">
/* svg style */
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 3px;
}
.node text {
font: 12px sans-serif;
}
.link {
fill: none;
stroke: #ccc;
stroke-width: 2px;
}
</style>
</head>
<body>
<div id="chart"></div>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/d3.min.js"></script>
<script type="text/javascript" src="js/tree.js"></script>
</body>
</html>
json
{
"success": true,
"data": {
"1": {
"id": "1",
"parent": "0",
"title": "根节点",
"url": "NULL",
"status": "0",
"shape": "root",
"product_id": "0",
"checkIfTrendAvailable": true,
"checkIfHeatAvailable": false
},
"2": {
"id": "2",
"parent": "1",
"title": "一级节点1",
"url": "NULL",
"status": "1",
"shape": "suqare",
"product_id": "300000001",
"checkIfTrendAvailable": false,
"checkIfHeatAvailable": false
},
"3": {
"id": "3",
"parent": "2",
"title": "三级节点1",
"url": "NULL",
"status": "1",
"shape": "square",
"product_id": "0",
"checkIfTrendAvailable": false,
"checkIfHeatAvailable": false
},
"4": {
"id": "4",
"parent": "2",
"title": "三级节点2",
"url": "NULL",
"status": "1",
"shape": "square",
"product_id": "0",
"checkIfTrendAvailable": false,
"checkIfHeatAvailable": false
},
"5": {
"id": "5",
"parent": "14",
"title": "子节点1",
"url": "NULL",
"status": 1,
"shape": "round",
"product_id": "0",
"checkIfTrendAvailable": true,
"checkIfHeatAvailable": false
},
"6": {
"id": "6",
"parent": "14",
"title": "子节点2",
"url": "NULL",
"status": 0,
"shape": "round",
"product_id": "0",
"checkIfTrendAvailable": true,
"checkIfHeatAvailable": false
},
"7": {
"id": "7",
"parent": "14",
"title": "子节点3",
"url": "NULL",
"status": 0,
"shape": "round",
"product_id": "0",
"checkIfTrendAvailable": true,
"checkIfHeatAvailable": false
},
"8": {
"id": "8",
"parent": "14",
"title": "子节点4",
"url": "NULL",
"status": 0,
"shape": "round",
"product_id": "0",
"checkIfTrendAvailable": true,
"checkIfHeatAvailable": false
},
"9": {
"id": "9",
"parent": "14",
"title": "子节点5",
"url": "NULL",
"status": 0,
"shape": "round",
"product_id": "0",
"checkIfTrendAvailable": true,
"checkIfHeatAvailable": false
},
"10": {
"id": "10",
"parent": "14",
"title": "子节点6",
"