您的位置:首页 > 其它

highChart动态生成图表一片空白

2016-02-18 17:32 232 查看
动态生成highChart的时候,

先把需要放图表的DIV 放到body里

var cellHistoryLine = $('<div id="cellHistoryLine" style="min-width:240px;height:280px;display:none;"></div>').appendTo('body');
再把图表放到  cellHistoryLine  DIV中

var cellHistoryLine = $('<div id="cellHistoryLine" style="min-width:240px;height:280px;display:none;"></div>').appendTo('body');
var cellcoverRoot = $('<div id="cellcoverRoot"></div>');            <pre name="code" class="javascript">                                         .
.
.
aa(cellName,historyRate);//生成图表

    var cellHistoryLine = $('#cellHistoryLine').appendTo(cellcoverRoot);//把图表DIV放到根DIV



function aa(cellName,historyRate){
var rateArray = new Array();
var dataArray = new Array();
cellName=cellName.replace(/图层/,"");
if(typeof(historyRate) != "undefined"&&historyRate!=null){

dataArray[0]="当前周"
var rateStringArray =historyRate.split(",");
//		alert(rateStringArray.length);
for(var i=0;i<rateStringArray.length;i++){
rateArray[i]=parseFloat(rateStringArray[i]);
dataArray[i]='前'+parseInt((rateStringArray.length)-i-1)+'周';
}
dataArray[rateStringArray.length-1]="当前周";
}
$('#cellHistoryLine').highcharts({
title: {
text: cellName,
x: -20 //center
},
credits: {
enabled: false
},
yAxis: {
title: {
text: '实装率(%)'
},
plotLines: [{
color:'red',
dashStyle:'solid',
value: 1,
width: 1,
color: '#808080'
}]
},
xAxis: {
//    	   title: {
//           text: '历史月份'
//       },
categories: dataArray,
},

series: [{
name: cellName,
data: rateArray
}],
});
}

然后再将图表生成到DIV中再appendTo 到根DIV中,

顺序       创建放图表的DIV到body中   》》动态生成图表放到 图表DIV中》》》再把已带图表DIV放到所需的DIV中 使用 appendTo()


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: