Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

javascript - js循环上的平均计算(Average calcul on js loop)

i'm trying to do a loop to add an average line on my d3js chart but i have a problem.

(我试图做一个循环,以在我的d3js图表上添加一条平均线,但我遇到了问题。)

I have this return that i try to adapt to return my average:

(我有这个回报,我试图适应以返回我的平均值:)

var param = copy.map(function(id) {
        return {
            id: id,
            values: data.map(d => {
                return {date: d.date, degrees: +d[id]}})
        };
    }); 

And i don't know how to modify it to give me the average at the "degree" attribute.

(而且我不知道如何修改它以在“度”属性下给我平均值。)

The +d increment the degree value with the id filter.

(+ d使用id过滤器递增度值。)

i already made this but it's only working when I have two charts on my graphic, i need to adapt the number of (+d[copy[n])) but I don't know how to do it

(我已经做过,但是只有当我的图形上有两个图表时,它才起作用,我需要调整(+ d [copy [n]))的数量,但是我不知道该怎么做)

var paramAvg = copy.map(function() {
        return {
            id: "Moyenne",
            values: data.map(d => {
                return {date: d.date, degrees: ((+d[copy[0]]) + (+d[copy[1]]) ) /copy.length}})
        };
    });

thanks for your help

(谢谢你的帮助)

  ask by VitoPepe translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...