Plotly:在堆积条形图的顶部显示数字的总和

问题描述

让我们使用以下 URL 中的示例:https://jsfiddle.net/d3fzsw25/

我想在堆积条形图的顶部显示总和。该值应显示为 45。

我尝试使用“文本”和“注释”方法显示我的总和。

一个计算总数的示例函数

    function getTotalY(graphData) {
    var total = [],undefined;
    for (var i = 0,n = graphData.length; i < n; i++) {
        var arg = graphData[i].y
        for (var j = 0,n1 = arg.length; j < n1; j++) {
            total[j] = (total[j] == undefined ? 0 : total[j]) + arg[j];
        }
    }
    return total.reduce(function (a,b) {
        return a + b;
    });
}

显示注释:

    function countTotal(graph) {
    var graphData = graph.data; //Loaded traces
    //making new layout
    var newLayout = {
  x: 'giraffes',y:getTotalY(graphData),mode: 'markers+text',name: 'Markers and Text',text: getTotalY(graphData),textposition: 'top',type: 'scatter'
  };
    Plotly.update('myDiv',graphData,newLayout)
}

我在 JS 中犯了什么错误吗?任何建议将不胜感激!谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)