6

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?

DR93
  • 463
  • 6
  • 21
  • 4
    Information in this question is very less. What type of chart is this? Where is your source code? How are you setting labels array data? Please provide a runnable snippet of your code so that people here can help you accordingly. – Vikasdeep Singh Sep 04 '18 at 13:20

2 Answers2

0

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
        }
    }
}],
anderssonola
  • 2,195
  • 16
  • 29
  • The above solution did not work out. I was able to hide the last label by drawing a rectangle canvas on it. Basically, label is there but it is hidden by the small white rectangle. I was able to get the pixel for the last label using getPixelForTick(index) function. – DR93 Sep 07 '18 at 08:53
  • We can access the label array in plugin using - chartInstance.config.data.labels – DR93 Sep 07 '18 at 08:54
0

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/

agravat.in
  • 561
  • 6
  • 14