jquery怎么实现关系图的绘制

 我来答
人啦哈w
推荐于2017-12-16 · 知道合伙人软件行家
人啦哈w
知道合伙人软件行家
采纳数:3947 获赞数:19705

向TA提问 私信TA
展开全部
实例代码如下:
<!DOCTYPE html >
<head>
<title>jQuery渐显效果的人物多级关系图</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<style type="text/css">
#box{width:500px;height:500px;position:relative;}
.host{position:absolute;width:100px;height:50px;line-height:50px;text-align:center;color:#000000;background-color:#eeeeee;border:#000000 1px solid;font-weight:bolder;}
.guest{position:absolute;width:80px;height:40px;line-height:40px;text-align:center;color:#999999;background-color:#FFFFFF;border:#000000 1px solid;cursor:pointer;}
.relationship{position:absolute;width:60px;height:20px;color:#aaa;line-height:20px;font-size:12px;text-align:center;}
</style>
<script src="http://www.codefans.net/ajaxjs/jquery1.3.2.js"></script>
<script type="text/javascript">
var relationName = [
{name:"成龙",friend:[
{name:"房祖名",relationship:"父子"},
{name:"林凤娇",relationship:"夫妻"},
},
{name:"房祖名",friend:[
{name:"成龙",relationship:"父子"},
{name:"林凤娇",relationship:"母子"},
},
{name:"林凤娇",friend:[
{name:"成龙",relationship:"夫妻"},
{name:"房祖名",relationship:"母子"},
},
{name:"吴绮莉",friend:[
{name:"成龙",relationship:"绯闻"},
{name:"林凤娇",relationship:"情敌"},
},
{name:"徐静蕾",friend:[
{name:"李亚鹏",relationship:"电影"},
{name:"韩寒",relationship:"娱乐圈"},
},
{name:"方大同",friend:[
{name:"房祖名",relationship:"情敌"},
{name:"薛凯琪",relationship:"否认拍拖"},
},
{name:"薛凯琪",friend:[
{name:"方大同",relationship:"否认拍拖"},
{name:"房祖名",relationship:"女友"}]
}
]
var relation = {
radius:150,
boxW:500,
boxH:500,
hostW:100,
hostH:50,
guestW:80,
guestH:40,
relationW:60,
relationH:20,
angle:0,
id:"box",
init:function(array,n){//传入参数1:数组 参数2:第几个
this.array = array;
this.appendHost(this.array,n);
this.appendQuest(this.array,n);
this.appendRelationShip(this.array,n);
},
appendHost:function(array,n){
var box = $("#"+this.id);
var host ="<span class='host'>"+array[n].name+"</span>";
box.append(host)
this.postHost();
},
postHost:function(){
var x = (this.boxW - this.hostW)/2;
var y = (this.boxH - this.hostH)/2;
$(".host").css({
left:x,
top:y
})
},
appendQuest:function(array,n){
var box = $("#"+this.id);
var guests="";
var that = this;
for(var i=0; i<array[n].friend.length; i++){
guests+="<span class='guest'>"+array[n].friend[i].name+"</span>";
}
$(guests).appendTo(box);
$(".guest").live("click",function(){
that.move(that,this);
})
this.postQuest();
},
postQuest:function(){
var guests = $(".guest");
var that = this;
guests.each(function(i){
guests.eq(i).css({
left:that.setQuestPose(guests.length,that.radius,i,that.guestW,that.guestH,that.angle).left,
top:that.setQuestPose(guests.length,that.radius,i,that.guestW,that.guestH,that.angle).top
}).attr("angle",i/guests.length)
})
},
setQuestPose:function(n,r,i,w,h,d){//n代表共几个对象 r代表周长 i代表第几个对象 w代表外面对象的宽带 h代表外面对象的高度 d代表其实角度
var p = i/n*Math.PI*2+Math.PI*2*d;
var x = r * Math.cos(p);
var y = r * Math.sin(p);
return {
"left":parseInt(this.boxW/2+ x - w/2),
"top":parseInt(this.boxH/2 + y - h/2)
}
},
appendRelationShip:function(array,n){
var box = $("#"+this.id);
var relation="";
for(var i=0; i<array[n].friend.length; i++){
relation+="<span class='relationship'>"+array[n].friend[i].relationship+"</span>";
}
box.append(relation);
this.postRelationShip();
},
postRelationShip:function(){
var guests = $(".relationship");
var that = this;
guests.each(function(i){
guests.eq(i).css({
left:that.setQuestPose(guests.length,that.radius/2,i,that.relationW,that.relationH,that.angle).left,
top:that.setQuestPose(guests.length,that.radius/2,i,that.relationW,that.relationH,that.angle).top
})
})
},
move:function(t,i){
var n = $(".guest").index($(i));
this.angle = parseFloat($(i).attr("angle"))+0.5;
this.delect(n);
this.moveHost(i);
this.moveQuest(i);
this.moveRelationship(i);
this.changeClass();
setTimeout(function(){t.newAppend(i)},500);
},
newAppend:function(i){
this.newAppendGuest(i,"guest","name",this.guestW,this.guestH,this.radius);
this.newAppendGuest(i,"relationship","relationship",this.relationW,this.relationH,this.radius/2);

},
newAppendGuest:function(i,className,name,w,h,r){
var host = $(i).html();
var guest = $(".guest").html();
var box = $("#"+this.id);
var that = this;
var next=0;
for(var i=0; i<this.array.length; i++){
if(host == this.array[i].name){
for(var j=0;j<this.array[i].friend.length; j++){
if(guest !== this.array[i].friend[j].name){
next++;
var guests ="<span class='"+className+"'>"+this.array[i].friend[j][name]+"</span>";
$(guests).appendTo(box).css({
left:that.setQuestPose(this.array[i].friend.length,r,next,w,h,that.angle).left,
top:that.setQuestPose(this.array[i].friend.length,r,next,w,h,that.angle).top
}).attr("angle",that.angle+next/this.array[i].friend.length).hide().fadeIn(1000);
}
}
}
}
},
moveHost:function(i){
var hLeft = parseInt($(".host").css("left")) + this.hostW/2;
var hTop = parseInt($(".host").css("top")) + this.hostH/2;
var gLeft = parseInt($(i).css("left")) + this.guestW/2;
var gTop = parseInt($(i).css("top")) + this.guestH/2;
var l = gLeft - hLeft;
var t = gTop - hTop;
var left = (hLeft - l - this.guestW/2)+"px";
var top = (hTop - t - this.guestH/2)+"px";
this.animate(".host",left,top);
},
moveRelationship:function(i){
var hLeft = parseInt($(".host").css("left")) + this.hostW/2;;
var hTop = parseInt($(".host").css("top")) + this.hostH/2;
var gLeft = parseInt($(".relationship").css("left")) + this.relationW/2;
var gTop = parseInt($(".relationship").css("top")) + this.relationH/2;
var l = gLeft - hLeft;
var t = gTop - hTop;
var left = (hLeft - l - this.relationW/2)+"px";
var top = (hTop - t - this.relationH/2)+"px";
this.animate(".relationship",left,top);
},
moveQuest:function(i){
var left = $(".host").css("left");
var top = $(".host").css("top");
this.animate(i,left,top);
},
delect:function(n){
$(".guest").slice(0,n).remove();
$(".guest").slice(1).remove();
$(".relationship").slice(0,n).remove();
$(".relationship").slice(1).remove();
},
animate:function(i,left,top){
$(i).animate({
left:left,
top:top
},500);
},
changeClass:function(){
var that =this;
$(".guest").addClass("abcdef").removeClass("guest");
$(".host").addClass("guest").removeClass("host").attr("angle",that.angle);
$(".abcdef").addClass("host").removeClass("abcdef").attr("angle",null);
}
}
$(document).ready(function(){
relation.init(relationName,0)
})
</script>
</head>
<body>
看不到效果,刷新一下就可以了;<br>
<div id="box"></div>
</body>
</html>
育知同创教育
2016-05-22 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
展开全部
jQuery只是一个DOM工具库,要绘图的话要采用其它技术配合,一般就是三种:VML(针对IE内核浏览器)、SVG、Canvas(针对支持HTML5的浏览器)。你可以看看百度的echarts、或者国外的D3.js。从功能角度讲,D3比echarts强大多了。不过echarts因为是百度的,所以中文文档多。
你说的关系图,可以用弦图(chord)或者力导向图(force)来表示。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
读醉不行
2016-06-15 · 超过25用户采纳过TA的回答
知道答主
回答量:48
采纳率:0%
帮助的人:28.1万
展开全部

不知道你要的关系图是怎么样的,我目前知道的就是d3.js有关于关系图的demo,就是关于力学图的

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
matlab爱好者
2021-01-23 · matlab编程与科研资料分享,欢迎关注!
matlab爱好者
采纳数:16 获赞数:28

向TA提问 私信TA
展开全部

本视频展示如何用matlab绘制散圆状态图,可用于相关科研数据绘图!

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友0baf361a5
2016-07-29 · TA获得超过214个赞
知道答主
回答量:123
采纳率:0%
帮助的人:45万
展开全部
可以用echarts http://echarts.baidu.com/ 很常用的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式