怎么把值传给series中的nodes节点和links
<%@ page language="java" import="java.util.*,jdbc.Record,com.google.gson.Gson,java.io.PrintWriter" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script src="Js/echarts.js"></script>
<script src="Js/theme/macarons.js"></script>
<script src="Js/jquery-3.1.1.min.js"></script>
<title>Echarts</title>
</head>
<body>
<% String json=(String)request.getAttribute("json");
%>
<div id="main" style="width: 1000px;height:600px;"></div>
<script type="text/javascript">
var myChart = echarts.init(document.getElementById('main'),'macarons');
var data = '<%=json%>';
var array = eval("("+data+")");
var nodes = [];
function createNode(){
var temp = {
id:0,
name:array[0].subj,
category:0,
symbolSize:50,
ignore:false,
flag:true
}
nodes.push(temp);
for(var i=1;i<(array.length+1);i++){
var temp1 = {
id:i,
name:array[i-1].obj,
category:1,
symbolSize:10,
ignore:true,
flag:true
}
nodes.push(temp1);
}
}
createNode();
var links = [];
function createLink(){
var temp = new Object();
for(var i=1;i<(array.length+1);i++){
var temp2 ={
source:nodes[0].id,
target:nodes[i].id
}
links.push(temp2);
}
}
createLink();
var option={
title: {
text:"echarts关系图demo"
},
series: [{
itemStyle: {
normal: {
label: {
position: 'top',
show: true,
textStyle: {
color: '#333'
}
},
nodeStyle: {
brushType: 'both',
borderColor: 'rgba(255,215,0,0.4)',
borderWidth: 1
},
linkStyle: {
normal: {
color: 'source',
curveness: 0,
type: "solid"
}
}
},
},
force:{
initLayout: 'circular',//初始布局
repulsion:100,//斥力大小
},
animation: false,
name:"",
type: 'graph',//关系图类型
layout: 'force',//引力布局
roam: true,//可以拖动
// legendHoverLink: true,//是否启用图例 hover(悬停) 时的联动高亮。
// hoverAnimation: false,//是否开启鼠标悬停节点的显示动画
// coordinateSystem: null,//坐标系可选
// xAxisIndex: 0, //x轴坐标 有多种坐标系轴坐标选项
// yAxisIndex: 0, //y轴坐标
// ribbonType: true,
useWorker: false,
minRadius: 15,
maxRadius: 25,
gravity: 1.1,
scaling: 1.1,
nodes:nodes,
links:links
}
]
};
myChart.setOption(option);
</script>
</body>
</html>