Chart.js 工具提示背景颜色设置

yoy*_*oma 5 chart.js

我正在尝试更改工具提示的背景颜色,但似乎只能更改键:https://jsfiddle.net/1ez0Lo8a/ 指的是当您将鼠标悬停在栏上时工具提示的黑色背景。

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

此外,正如您所看到的,我已经设法删除了该轴 - 但这些设置都没有删除最底部的水平轴。任何人都可以建议如何删除那个吗?

Nih*_*kar 10

直接在tooltips下使用backgroundColor属性。

试试这个代码:

 tooltips: {
                    yAlign: 'bottom',
                    callbacks: {
                        labelColor: function(tooltipItem, chart) {
                            return {
                                backgroundColor: 'rgb(255, 0, 0)'
                            }
                        },
                    },
            backgroundColor: '#227799'
                }
Run Code Online (Sandbox Code Playgroud)