How get sum of total values in stackedBar ChartJs

前端 未结 6 1542
执笔经年
执笔经年 2021-02-05 14:06

I\'m trying to get the sum of all values of a stackedBar and include this total in tooltip.

Note: my datasets aren\'t static, this is an example

6条回答
  •  一向
    一向 (楼主)
    2021-02-05 15:07

    Shorter version of Gaspar's answer:

    tooltips: {
      callbacks: {
        footer: (tooltipItems, data) => {
          let total = tooltipItems.reduce((a, e) => a + parseInt(e.yLabel), 0);
          return 'Total: ' + total;
        }
      }
    }
    

    Example: https://jsfiddle.net/g3ba60zc/2/

提交回复
热议问题