Chartjs-Chart.js 2 How will I put the dataset inside the bar if it is near the TOP?

0👍

I just found the answer, I edited the else{} block under verticalLabel function:

function verticalLabel(ctx, data, dataToSplit, topOffset, spaceBetween, commaGap, why_pos) {
    var i = 0, prev = 0;

    for (x of dataToSplit.toString().split("").reverse()) {
       if (x.indexOf(",") > -1) {
        ctx.fillText(x, data.x + commaGap, prev - topOffset / why_pos);
        } else {
        ctx.fillText(x, data.x, why_pos - spaceBetween * i - topOffset / why_pos);
        i++;
            }
        var prev = data.y - spaceBetween * i;
        }   
    }

my code under animation: {}

if ((scale_max - model.y) / scale_max >= 0.60)
    y_pos = model.y + 90; 
    verticalLabel(ctx, model, addCommas(dataset.data[i]), 50, 20, 4, y_pos);

almost there graph

It is somehow working but still not perfect. I LOST the COMMAS when inserted inside the bar graph. I still need help.

Leave a comment