score:2

Accepted answer

You can handle this in the legendItemClick event:

legendItemClick: function () {
    var thisSeries = this;
    var tot = 0, num = 0; 
    var aveSeries = null;
    this.chart.series.forEach(function(d,i){
       if (d.name == "Average"){
           aveSeries = d;
           return;
       }
        if (thisSeries == d && d.visible){
           return;
        }
       if (thisSeries != d && !d.visible){
           return;
       }
       tot += d.data[0].y;
       num += 1.0;
    });
    var ave = tot/num;
    aveSeries.setData([ave]);
 }

Updated fiddle here.

score:0

Thanks! Just before your post I saw the legendItemClick, and from there I almost got it by myself, but your code helped me to the final result.

However, my original plan was to make it work with multiply series so I had some problem until I finally got to a working result.

This is the finished result:

legendItemClick: function(){
    var tot=0,num=0,avg=0;
    thisSeries=this;
    if(this.name=="Average"){
        return false;
    }
    this.data.forEach(function(ser,serI){
        ser.series.chart.series.forEach(function(col,colI){
            if(col.name=="Average"){
                avgCol=col;
                return;
            }
            if(thisSeries==col && col.visible){
                return;
            }
            if(thisSeries!=col && !col.visible){
                return;
            }
            tot+=col.data[serI].y;
            num++;
        });
        avg=tot/num;
        tot=0;
        num=0;
        avgCol.data[serI].update(avg);
    });
}

updated fiddle here: http://jsfiddle.net/skorpion/L5chyc3e/

/Niclas


Related Query

More Query from same tag