如何在d3 treemap中设置多个文本?

时间:2016-05-30 04:17:58

标签: javascript d3.js nvd3.js



<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script src="d3.min.js"></script>
</head>
<body>
<script>
var color = d3.scale.category10();
var canvas = d3.select('body').append('svg')
  .attr('width',800)
  .attr('height',500)
d3.json('mydata.json',function (data){
	var treemap = d3.layout.treemap()
	  .size([800,500])
	  .nodes(data)
	var cells = canvas.selectAll(".cell")
	  .data(treemap)
	  .enter()
	  .append("g")
	  .attr("class","cell")
	cells.append("rect")
	  .attr("x",function (d) { return d.x; })
	  .attr("y",function (d) { return d.y; })
	  .attr("width",function (d) { return d.dx; })  
	  .attr("height",function (d) { return d.dy; }) 
	  .attr("fill",function (d) { return d.children ? null : color(d.parent.name); })
	  .attr("stroke",'#fff')    
	cells.append("text")
	  .attr("x",function (d) { return d.x + d.dx / 2 })
	  .attr("y",function (d) { return d.y + d.dy / 2 })
	  .attr("text-anchor", "middle")
	  .text(function (d) { return d.children ? null : d.name; })   
})  
</script>
</body>
</html>
&#13;
&#13;
&#13;

这是我用于创建treemap的d3代码。在文本部分我必须显示多个文本。现在它只显示d.name但我必须显示d.name和d.value ...如何显示多个d3 treemap中的文字?

{     &#34;姓名&#34;:&#34; Max&#34;,     &#34;价值&#34;:100,     &#34;孩子&#34;:[     {       &#34;姓名&#34;:&#34; Sylvia&#34;,       &#34;价值&#34;:75,       &#34;孩子&#34;:[       {&#34; name&#34;:&#34; Craig&#34;,&#34; value&#34;:25},       {&#34; name&#34;:&#34; Robin&#34;,&#34; value&#34;:25},       {&#34; name&#34;:&#34; Anna&#34;,&#34; value&#34;:25}       ]     },     {     &#34;姓名&#34;:&#34;大卫&#34;,     &#34;价值&#34;:75,     &#34;的子&#34;:[      {&#34; name&#34;:&#34; jeff&#34;,&#34; value&#34;:25},      {&#34; name&#34;:&#34; Buffy&#34;,&#34; value&#34;:25}      ]     },     {     &#34;姓名&#34;:&#34; X先生&#34;,     &#34;值&#34; 75     }     ] } 这是我的json文件。

1 个答案:

答案 0 :(得分:2)

只需为值添加另一个文本并调整y。

string strPasswordCertificate = "123456";
string strCertificate = "C:/Test/AUTH_RSA_db79bb07b4722c042e025979b3b11995fc46765b.p12";
X509Certificate x509_CertAUTH = new X509Certificate(strCertificateFilePathAUTH, strPasswordCertificate);
string strCertAUTH = x509_CertAUTH.ToString();

CreateSessionRequest CreateReq = new CreateSessionRequest();

CreateReq.x509Certificate = strCertAUTH;
string strIIN = "753159846249";

CreateReq.tin = strIIN;
WS.createSession(CreateReq);

string _userName = "123456789011";
string _UserPassword = "TestPass123";

UsernameToken userToken;

userToken = new UsernameToken(_userName, _UserPassword, PasswordOption.SendPlainText);

SessionService WS = new SessionService();
SoapContext requestContext = WS.RequestSoapContext;
requestContext.Security.Tokens.Add(userToken);

WS.createSession(CreateReq);

工作代码here