導航:首頁 > 編程語言 > 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樹形圖相關的資料

熱點內容
大多多電影網台灣倫理片 瀏覽:473
小米8分類文件找不到 瀏覽:667
國外電影中的女惡魔 瀏覽:808
找不到文件 瀏覽:656
女人的戰爭之消失的眼角膜電影 瀏覽:694
東南亞四級片介紹 瀏覽:959
道士強奸僵屍 瀏覽:541
含糖1v1荔枝筆趣閣 瀏覽:761
app有什麼免費的電影 瀏覽:523
龍棺命燈 瀏覽:221
win7關機自動關閉程序 瀏覽:918
給力引擎傳奇版本 瀏覽:14
代碼復查的方法 瀏覽:838
linux查看輸出 瀏覽:620
哪些網路電話有話費贈送 瀏覽:831
里水哪裡有學Ug編程的 瀏覽:501
plc機器手臂編程用什麼軟體 瀏覽:189
法國啄木鳥黑絲大奶寡婦 瀏覽:163
像金十數據的手機app有哪些 瀏覽:671
intimacy法國觀看 瀏覽:768

友情鏈接