最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chartjs - show elements in all datasets on hover using bar chart - Stack Overflow

programmeradmin5浏览0评论

Is there a way to show the elements together when hovering on the same x-axis of a bar chart? Same with the image below.

I tried hover.mode ('single', 'label' and 'x-axis')

options: {
    hover: {
        // Overrides the global setting
        mode: 'label'
    }
}

Unfortunately it did not work for some reason. Is this not possible or did I miss something?

Code here: /

Thanks.

Is there a way to show the elements together when hovering on the same x-axis of a bar chart? Same with the image below.

I tried hover.mode ('single', 'label' and 'x-axis')

options: {
    hover: {
        // Overrides the global setting
        mode: 'label'
    }
}

Unfortunately it did not work for some reason. Is this not possible or did I miss something?

Code here: https://jsfiddle.net/jk4bg8a2/

Thanks.

Share Improve this question asked Sep 22, 2016 at 18:33 razraz 4096 silver badges18 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 14

The property is actually stored in tooltips like this :

options: {
    tooltips: {
        // Overrides the global setting
        mode: 'label'
    }
}

Check your updated fiddle to see it working, and here is its result :

For Chart.js 3.7.1 this is what worked for me

options: {
    interaction: {
        mode: 'index'
    }
}

Documented under ChartJs Interactions Documentation

For Chart.js 3, label mode is replaced by index and tooltips should be placed as tooltip in plugin object.

Below is working for chartjs 3.

plugins: {
  tooltip: {
    mode: 'index',
    position: 'average',
  }
}
发布评论

评论列表(0)

  1. 暂无评论