最近做作業,需要實作用echarts在頁面上顯示關系圖,代碼寫好了不報錯了,但是頁面一直顯示loading就是不加載影像,后面dao層Servlet什么的都沒問題,想請問大佬們告訴我哪個地方寫錯了,應該怎么寫才行,謝謝了!下面是jsp代碼:

<script type="text/javascript">
var myChart = echarts.init(document.getElementById('main1'));
myChart.showLoading();
var option = {
title: {
text: '關鍵ipc小類共現圖譜分析'
},
animationDurationUpdate: 1500,
animationEasingUpdate: 'quinticInOut',
series : [
{
type: 'graph',
layout: 'none',
// progressiveThreshold: 700,
data:(function(){
var dataArr =[];
$.ajax({
url: "jishucoripc.do",
dataType: "json",
type: "post",
async: false,
data : {},
success : function(result){
if (result) {
for(var j = 0;j<result.length;j++){
//if(data[j].lt_status=="001"){
console.log(result[j].source);
console.log(result[j].weight);
var obj = {
x: Math.random(),
y: Math.random(),
id:result[j].source,
name : result[j].source,
symbolSize: result[j].weight,
itemStyle: {
color: function writeRandomColor(){
var rand = Math.round(Math.random() * 0x1000000);
var color = "00000".concat(rand.toString(16));
document.write("#" + color.substr(color.length - 6, 6));
}
}
};
dataArr.push(obj);
}}}
}
);
return dataArr;
})(),
edges :(function(){
var linkArr = [];
$.ajax({
url: "jishucoripc.do",
dataType: "json",
type: "post",
data : {},
async: false,
success : function(result){
if (result) {
for(var j = 0;j<result.length;j++){
//if(data[j].lt_status=="001"){
console.log(result[j].source);
console.log(result[j].target);
var link = {
source : result[j].source,
target : result[j].target,
};
linkArr.push(link);
}
}
}
})();
return linkArr;}),
emphasis: {
label: {
position: 'right',
show: true
}
},
roam: true,
focusNodeAdjacency: true,
lineStyle: {
width: 0.5,
curveness: 0.3,
opacity: 0.7
}
}
]
};
myChart.setOption(option);
</script>
下面是官網上的Demo:
myChart.showLoading();
$.getJSON(ROOT_PATH + 'data/asset/data/npmdepgraph.min10.json', function (json) {
myChart.hideLoading();
myChart.setOption(option = {
title: {
text: 'NPM Dependencies'
},
animationDurationUpdate: 1500,
animationEasingUpdate: 'quinticInOut',
series : [
{
type: 'graph',
layout: 'none',
// progressiveThreshold: 700,
data: json.nodes.map(function (node) {
return {
x: node.x,
y: node.y,
id: node.id,
name: node.label,
symbolSize: node.size,
itemStyle: {
color: node.color
}
};
}),
edges: json.edges.map(function (edge) {
return {
source: edge.sourceID,
target: edge.targetID
};
}),
emphasis: {
label: {
position: 'right',
show: true
}
},
roam: true,
focusNodeAdjacency: true,
lineStyle: {
width: 0.5,
curveness: 0.3,
opacity: 0.7
}
}
]
}, true);
});
uj5u.com熱心網友回復:
2個ajax回傳結果后再呼叫setOption,別忘了hideLoadinguj5u.com熱心網友回復:
data edges 先請求好,在回呼里面給option賦值轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/51615.html
標籤:JavaScript
上一篇:添加draggable屬性后,input的內容不能用滑鼠選中
下一篇:ajax異步和同步的執行順序問題
