2013-10-31 59 views
0

我有几个图表根据数组数据添加id,然后根据它们的id将它们呈现给特定的图表。正在添加ID,但新图表数据未被更新。我的代码有什么问题?highcharts添加新的系列不工作

My_jsfiddle

$('.bars').each(function(){  
    bars = new Highcharts.Chart({ 
      chart: {type:'bar',renderTo:this,backgroundColor:'#222',plotBorderWidth:0,plotBackgroundColor:{linearGradient:{ x1:0, y1:0, x2:0, y2:1 },stops: [[0.40, "#383838"],[1, "#000"],[0.50, "#383838"]]},plotBorderColor:'#a6a0a0',height:70}, 
      title: {align:'left',margin:5,style: {color:'#FFFFFF',fontSize:'10px',"text-transform":"uppercase"}},legend: {enabled:false},credits: {enabled:false},tooltip:{enabled:false}, 
      loading:{labelStyle:{fontWeight:'bold',color:'#FF0000',top:'10%'},style:{backgroundColor:'#222'},hideDuration:1000}, 
      xAxis: {labels: {enabled:false},tickWidth:0,tickInterval:0,gridLineWidth:0}, 
      yAxis: {labels: {enabled:false},title: {text:null},min:0,max:100,tickWidth:0,gridLineWidth:0}, 
      series: [{data:[5]}] 
    }); 

}); 

function test(){ 
    while(bars.series.length){ 
     bars.series[0].remove(); 
    } 
var idS = [50,60,40,80], 
    horiz = document.getElementById('horizBarGauage'), 
    idSL = 4, 
    j; 
for (j=idSL;j--;){ 
    console.log('Logging', idS[j]); 
     horiz.children[j].id = idS[j]; 
     console.log('Logging', horiz.children[j].id); 
     var idData = idS[j]; 
     bars.renderTo = idData; 
     bars.addSeries({data:[idData]}); 
     bars.redraw();    
    }   
} 

test(); 

回答

1

每次创建一个图表时,bars是被重置到新的图表。因此,在test()中,当您参考bars时,它使用最近创建的图表。

test()你需要找到实际的图表,你什么编辑:

var chart = $("#" + idS[j]).highcharts(); 
chart.addSeries({data: [idData] });