How to disable chartjs tooltip on mibile devices and small screens?

僤鯓⒐⒋嵵緔 提交于 2020-03-05 03:40:10

问题


I have to many points on my chart so when I am clicking through on mobile or small screen my tooltip just showing data from multiple points:

I researched on that and find out the the best approach would be is to disable the tooltip on small screens. I tried to follow this advice from the docs. But have no luck:

options: {
        // This chart will not respond to mousemove, etc
        events: ['click']
    }

Also I found that but I think it is actually related to what I just did based on the advice form the docs.

Any ideas how to fix?


回答1:


Tooltips can be disabled in the options as shown below (see Tooltip Configuration):

option: 
    tooltips: {
        enabled: false
    }
    ...
}

Instead of using a hard coded value false, you may obtain the value from a function that returns true or false depending on the screen size.

option: 
    tooltips: {
        enabled: window.screen.width > 400
    }
    ...
}

I've no experience in creating web apps for mobile devices. Therefore 400 is probably not the right choice. The following answer should help finding the appropriate function: https://stackoverflow.com/a/11381730/2358409



来源:https://stackoverflow.com/questions/60132952/how-to-disable-chartjs-tooltip-on-mibile-devices-and-small-screens

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!