0

I have a mixed chart of bar and line graphs. Both are showing their data labels but I only want the bar graph to show its own data labels and not the line graph.

I've got this code from How to show data values or index labels in ChartJs (Latest Version)

How should I tweak it?

animation: {
       onComplete: function() {
           var ctx = this.chart.ctx;
           ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontSize, Chart.defaults.global.defaultFontStyle, Chart.defaults.global.defaultFontFamily);
           ctx.fillStyle = "white";
           ctx.textAlign = "center";
           ctx.textBaseline = "bottom";

           this.data.datasets.forEach(function (dataset) 
           {
                for( var i = 0; i < dataset.data.length; i++ )
                {
                     for(var key in dataset._meta)
                     {
                         var model = dataset._meta[key].data[i]._model;
                         ctx.fillText(dataset.data[i], model.x, model.y+15);
                     }
                 }
            });
       }
}

0 Answers0