Chartjs-Show highest value untop of a bars when dataset is stacked (chartjs)

1👍

check out this jsfiddle: https://jsfiddle.net/umsbywLg/2/

essentially I calculated the max value and then drew that on top on the stacked bars:

onComplete: function() {                                                                       
               var ctx = this.chart.ctx;
               var chart = this;
               ctx.textAlign = "center";
               ctx.textBaseline = "middle";

               var datasets = this.config.data.datasets;

               ctx.font = "15px QuickSand"; 
               ctx.fillStyle = "#303030";

               datasets.forEach(function (dataset, i) {
                    var maxValue = 0;
                    chart.getDatasetMeta(i).data.forEach(function (p, j) {
                        if(maxValue < datasets[j].data[i]) {
                            maxValue = datasets[j].data[i];
                        }
                    });

                    ctx.fillText(maxValue, datasets[i]._meta[0].data[i]._view.x, 20);        
               });
           } 

Leave a comment