JavaScript How to display inline values in a stacked bar chart with Chart.js? display variable values inline while debugging

I am using the Chart.js library to display some values in stacked bars but I am struggling in trying to find out how to display the values inside of the bars, that is,

enter image description here

Right now, I have the following code that displays the numbers on top of the bars but I would like to know how can I display them inside of the bars.

var numberWithCommas = function(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  };

var dataPack1 = [50000, 22000, 26000, 35000, 55000, 55000, 56000, 59000, 60000, 61000, 60100, 62000];

var dataPack2 = [0, 6000, 13000, 14000, 50060, 20030, 20070, 35000, 41000, 4020, 40030, 70050];

var dates = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

// Chart.defaults.global.elements.rectangle.backgroundColor = '#FF0000';

var bar_ctx = document.getElementById('bar-chart');
var bar_chart = new Chart(bar_ctx, {
    type: 'bar',
    data: {
        labels: dates,
        datasets: [
        {
            label: 'SoftEnterprises, Sales',
            data: dataPack1,
						backgroundColor: "rgba(55, 160, 225, 0.7)",
						hoverBackgroundColor: "rgba(55, 160, 225, 0.7)",
						hoverBorderWidth: 2,
						hoverBorderColor: 'lightgrey'
        },
        {
            label: 'SmartSystems, Sales',
            data: dataPack2,
						backgroundColor: "rgba(225, 58, 55, 0.7)",
						hoverBackgroundColor: "rgba(225, 58, 55, 0.7)",
						hoverBorderWidth: 2,
						hoverBorderColor: 'lightgrey'
        },
        ]
    },
    options: {
     		animation: {
        	duration: 10,
          onComplete: function(){
                var chartInstance = this.chart,
                ctx = chartInstance.ctx;
                ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize, Chart.defaults.global.defaultFontStyle, Chart.defaults.global.defaultFontFamily);
                ctx.textAlign = 'center';
                ctx.textBaseline = 'bottom';
                ctx.fillStyle = '#000';
                                this.data.datasets.forEach(function(dataset, i) {
                var isHidden = dataset._meta[0].hidden; //'hidden' property of dataset
                if (!isHidden) { //if dataset is not hidden
                    var meta = chartInstance.controller.getDatasetMeta(i);
                    meta.data.forEach(function(bar, index) {
                    var data = dataset.data[index];
                    ctx.fillText(data, bar._model.x, bar._model.y - 5);
                });
               }
            });
          
          }
        },
        tooltips: {
					mode: 'label',
          callbacks: {
          label: function(tooltipItem, data) { 
          	return data.datasets[tooltipItem.datasetIndex].label + ": " + numberWithCommas(tooltipItem.yLabel);
          }
          }
         },
        scales: {
          xAxes: [{ 
          	stacked: true, 
            gridLines: { display: false },
            }],
          yAxes: [{ 
          	stacked: true, 
            ticks: {
        			callback: function(value) { return numberWithCommas(value); 
              },
     				}, 
            }],
        }, // scales
        legend: {display: true}
    } // options
   },
   
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>

<canvas id="bar-chart" width="600" height="350"></canvas>
Answer:1

I'm trying to override the default TinyMce 4 spellchecker method "markErrors", but without success. I've already tried: // on editor init... editor.plugins.spellchecker.markErrors = function() { ...

I'm trying to override the default TinyMce 4 spellchecker method "markErrors", but without success. I've already tried: // on editor init... editor.plugins.spellchecker.markErrors = function() { ...

I'm surprised that the following code works: while(fred !== "stop"){ var fred = prompt("Should I stop or go?") }; I'd understand this in a do while loop: do { code to be executed at least ...

I'm surprised that the following code works: while(fred !== "stop"){ var fred = prompt("Should I stop or go?") }; I'd understand this in a do while loop: do { code to be executed at least ...

  1. javascript while loop break
  2. javascript while loop example
  3. javascript while loop continue
  4. javascript while loop with delay
  5. javascript while loop wait
  6. javascript while loop with timeout
  7. javascript while loop mdn
  8. javascript while loop async
  9. javascript while loop wait for promise
  10. javascript while loop countdown
  11. javascript while loop with multiple conditions
  12. javascript while loop synchronous
  13. javascript while loop through array
  14. javascript while loop await
  15. javascript while loop promise
  16. javascript while loop even numbers
  17. javascript while loop one line
  18. javascript while loop two conditions
  19. javascript while loop not breaking
  20. javascript while loop not equal

I have a simple requirement: Based on the response of a user on a particular yes no question, show him another question. The issue is I am using Bootstrap forms so all my div classes are named form-...

I have a simple requirement: Based on the response of a user on a particular yes no question, show him another question. The issue is I am using Bootstrap forms so all my div classes are named form-...

I'm having trouble with IntelliJ Idea's code completion and syntax checking and JavaScript. I have the following (simplified) code for a Singleton object: var MySingleton = new function() { var ...

I'm having trouble with IntelliJ Idea's code completion and syntax checking and JavaScript. I have the following (simplified) code for a Singleton object: var MySingleton = new function() { var ...