导航:首页 > 编程语言 > d3js树形图

d3js树形图

发布时间:2022-01-19 17:12:07

❶ 如何使d3js的力学关系图固定下来

使d3js的力学关系图固定下来方法如下:

1、布局的事件

代码中,假设定义如下的布局:

❷ d3.js画力学图,怎么把图限制在边框内

我上次看了,他这个都明白了,你可以看看,他每一步都有代码,注释,很简单的。

网页链接

❸ 如何用d3.js画通信网络的体系结构

以下代码示例中,用于表示交互的树:

[html] view plain print?
<!DOCTYPE html>
<meta charset="utf-8">
<style>

.node {
cursor: pointer;
}

.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}

.node text {
font: 10px sans-serif;
}

.link {
fill: none;
stroke: #ccc;

❹ 如何使用d3.js制作可视化图表

D3是目前最流行的JavaScript可视化图表库之一,D3的图表类型非常丰富,并且支持SVG格式,因此应用十分广泛,也有很多图表插件基于D3开发,比如MetricsGraphics.js,在D3上构建的数据图表非常强大。


D3的特点

允许绑定任意数据到DOM,将数据驱动转换应用到Document中。

不仅可以创建精美的HTML表格,而且可以绘制折线图、柱形图和饼图等数据图表。

支持SVG,在Web页面上渲染毫无压力。

回到顶部

D3的使用方法

关于D3的具体用法,可以看D3图形库API参考这篇文章。本文主要对介绍一些经典图表的实现效果及代码。



<!DOCTYPEhtml>
<metacharset="utf-8">
<style>

svg{
font:10pxsans-serif;
}

.y.axispath{
display:none;
}

.y.axisline{
stroke:#fff;
stroke-opacity:.2;
shape-rendering:crispEdges;
}

.y.axis.zeroline{
stroke:#000;
stroke-opacity:1;
}

.title{
font:30078pxHelveticaNeue;
fill:#666;
}

.birthyear,
.age{
text-anchor:middle;
}

.birthyear{
fill:#fff;
}

rect{
fill-opacity:.6;
fill:#e377c2;
}

rect:first-child{
fill:#1f77b4;
}

</style>
<body>
<scriptsrc="http://d3js.org/d3.v3.min.js"></script>
<script>

varmargin={top:20,right:40,bottom:30,left:20},
width=960-margin.left-margin.right,
height=500-margin.top-margin.bottom,
barWidth=Math.floor(width/19)-1;

varx=d3.scale.linear()
.range([barWidth/2,width-barWidth/2]);

vary=d3.scale.linear()
.range([height,0]);

varyAxis=d3.svg.axis()
.scale(y)
.orient("right")
.tickSize(-width)
.tickFormat(function(d){returnMath.round(d/1e6)+"M";});

//AnSVGelementwithabottom-rightorigin.
varsvg=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+")");

//.
varbirthyears=svg.append("g")
.attr("class","birthyears");

//Alabelforthecurrentyear.
vartitle=svg.append("text")
.attr("class","title")
.attr("dy",".71em")
.text(2000);

d3.csv("population.csv",function(error,data){

//Convertstringstonumbers.
data.forEach(function(d){
d.people=+d.people;
d.year=+d.year;
d.age=+d.age;
});

//.
varage1=d3.max(data,function(d){returnd.age;}),
year0=d3.min(data,function(d){returnd.year;}),
year1=d3.max(data,function(d){returnd.year;}),
year=year1;

//Updatethescaledomains.
x.domain([year1-age1,year1]);
y.domain([0,d3.max(data,function(d){returnd.people;})]);

//[male,female].
data=d3.nest()
.key(function(d){returnd.year;})
.key(function(d){returnd.year-d.age;})
.rollup(function(v){returnv.map(function(d){returnd.people;});})
.map(data);

//.
svg.append("g")
.attr("class","yaxis")
.attr("transform","translate("+width+",0)")
.call(yAxis)
.selectAll("g")
.filter(function(value){return!value;})
.classed("zero",true);

//(sothatnoenterorexitisrequired).
varbirthyear=birthyears.selectAll(".birthyear")
.data(d3.range(year0-age1,year1+1,5))
.enter().append("g")
.attr("class","birthyear")
.attr("transform",function(birthyear){return"translate("+x(birthyear)+",0)";});

birthyear.selectAll("rect")
.data(function(birthyear){returndata[year][birthyear]||[0,0];})
.enter().append("rect")
.attr("x",-barWidth/2)
.attr("width",barWidth)
.attr("y",y)
.attr("height",function(value){returnheight-y(value);});

//Addlabelstoshowbirthyear.
birthyear.append("text")
.attr("y",height-4)
.text(function(birthyear){returnbirthyear;});

//Addlabelstoshowage(separate;notanimated).
svg.selectAll(".age")
.data(d3.range(0,age1+1,5))
.enter().append("text")
.attr("class","age")
.attr("x",function(age){returnx(year-age);})
.attr("y",height+4)
.attr("dy",".71em")
.text(function(age){returnage;});

//.
window.focus();
d3.select(window).on("keydown",function(){
switch(d3.event.keyCode){
case37:year=Math.max(year0,year-10);break;
case39:year=Math.min(year1,year+10);break;
}
update();
});

functionupdate(){
if(!(yearindata))return;
title.text(year);

birthyears.transition()
.ration(750)
.attr("transform","translate("+(x(year1)-x(year))+",0)");

birthyear.selectAll("rect")
.data(function(birthyear){returndata[year][birthyear]||[0,0];})
.transition()
.ration(750)
.attr("y",y)
.attr("height",function(value){returnheight-y(value);});
}
});

❺ d3js做的图表怎么放在html中的指定位置啊

定义div的id,比如为id1,定义svg时用d3.select("#id1")而不是d3.select("body")

❻ c#winform中能做出类似于d3js的效果的动态风向图吗

可以http://blog.csdn.net/xianfajushi/article/details/9469353

❼ d3.js怎样做出大数据可视化图

d3.js 是一个现成的库,需要通过html 调用 d3.js的库,使用库里面不同的图形模块结合数据,做成可视化的图的是需要指定数据。

❽ d3js做的图标怎么放在html中的指定位置

1、利用抄js代码首先创建一个袭div,document.createElement('div'); 2、确认div添加位置,可以在某个dom元素后面,或者通过css属性控制具体位置,主要通过left/top等属性控制。 3、确定位置之后,显示div即可。 示例:比如html中有一个文本输入框,

❾ d3js的tree结构图例怎么做

如下过程:
使用d3.js
初始化d3和画布大小,tree = d3.layout.cluster().size([h, w])
导入数据,使用d3默认处理数据: root = tree.nodes(data)
处理数据(包括坐标的处理)
展示数据
思路是这样的。

阅读全文

与d3js树形图相关的资料

热点内容
这个电影关于飞机的英语 浏览:652
晚娘类似电影推荐 浏览:945
关于保姆的韩国电影 浏览:907
韩剧大尺度男主电影 浏览:856
同性电影男生 浏览:568
苹果手机看片网址 浏览:616
风月片网站动漫 浏览:765
按摩院电影泰国 浏览:982
沐风之女无删除版百度网盘 浏览:334
女主角叫珍妮的美国电影 浏览:838
庐江电影 浏览:455
电影龙棺命灯免费在线观看 浏览:549
电影吃奶 浏览:690
变形金刚2超清国语版下载 浏览:816
周星驰赌神系列电影 浏览:895
有一部韩国电影老公是废材老婆开了个美容店 浏览:984
恐怖电影在线观看 浏览:697
啄木鸟 电影 浏览:913
xhmb77 浏览:526
男主角叫顾北的小说 浏览:56

友情链接