5

I am trying to change the background color of the tooltip, but can only seem to change the key: https://jsfiddle.net/1ez0Lo8a/ Referring to the black background of the tooltip when you hover over the bar.

tooltips: {
                yAlign: 'bottom',
                callbacks: {
                    labelColor: function(tooltipItem, chart) {
                        return {
                            backgroundColor: 'rgb(255, 0, 0)'
                        }
                    },
                }

Further, as you can see, I've managed to remove the axis - but none of those settings have removed the very bottom horizontal axis. Can anyone advise how to remove that one also ?

yoyoma
  • 3,336
  • 6
  • 27
  • 42
  • https://stackoverflow.com/questions/25338141/chart-js-custom-tooltip-option/25338881#25338881 this may be of some help – lovemyjob May 22 '18 at 08:10

2 Answers2

10

Use backgroundColor property directly under tooltips .

Try this code :

 tooltips: {
                    yAlign: 'bottom',
                    callbacks: {
                        labelColor: function(tooltipItem, chart) {
                            return {
                                backgroundColor: 'rgb(255, 0, 0)'
                            }
                        },
                    },
            backgroundColor: '#227799'
                }
Nihar Sarkar
  • 1,187
  • 1
  • 13
  • 26
  • How can I pass function to bacjground color in order to do conditional ? I think it accepts only string ? – infodev Mar 01 '19 at 12:52
  • write conditions inside a method and return color hashcode as string and just call that method from backgroundColor property . for example , the method name is x which is returning the color code. then the code will be `backgroundColor: x()` – Nihar Sarkar Mar 01 '19 at 15:39
0

tooltips: { backgroundColor: '...'} is works, but for dynamical change of background with depend of element (when argument is function) I had to do patch in 3 places of unpacked code of bundle, version 2.7.3 (it may be in higher versions also).

Sp Mbt
  • 1