highcharts添加新的系列不工作 [英] highcharts Adding New Series Not Working

查看:105
本文介绍了highcharts添加新的系列不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have several charts that are added ids according to array data then they are rendered to the a particular chart according to its id. The ids are being added but the new chart data is not being updated. What is wrong with my code?

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();


推荐答案

每次创建图表时, c> bars 正在重置为新的图表。因此,当您引用 bars 时,它在 test()中使用最近创建的图表。

Each time you create a chart, bars is being reset to that new chart. So in test() when you reference bars, it is using the most recently created chart.

test()中,您需要找到您要编辑的实际图表:

In test() you need to find the actual chart that you what to edit:

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

这篇关于highcharts添加新的系列不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆