How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?

Viewed 380

I want to hide the last label in the chart. It is not a static array, data keeps on coming. Hence the last label cannot be just set to blank or null value. Is there any chartjs option to hide it or how to access labels array in chart plugin?

2 Answers

Depending on your needs you can use the ticksoption to modify the labels. Do your checks of value and return based on your needs. docs

yAxes: [{
    ticks: {
        callback: function(value, index, values) {
            return value
        }
    }
}],

Just set the label and tooltip options like so

...
options: {
    legend: {
        display: false
    },
    tooltips: {
        callbacks: {
           label: function(tooltipItem) {
                  return tooltipItem.yLabel;
           }
        }
    }
}

Fiddle - http://jsfiddle.net/g19220r6/

Related