简体   繁体   English

c3.js - 如何在条形图上显示手形光标悬停

[英]c3.js - how to show hand cursor on bar chart hover

In pie charts c3js by default shows a hand cursor (pointer) when pie slice is hovered. 在饼图中,c3js默认显示悬停饼图时的手形光标(指针)。 I would like to have the same behavior for each bars in a bar chart. 我想对条形图中的每个条形图具有相同的行为。 How to achieve that? 怎么实现呢?

I tried the below css but it shows the hand cursor even when you hover in between 2 bars. 我尝试了下面的css但它显示了手形光标,即使你在2个小节之间悬停。

.c3-event-rect {
    cursor:pointer;
}

To clarify this is a jsfiddle example I'd like to have pointer cursor only on bar items because only them are clickable. 为了澄清这是一个jsfiddle示例我想只在条形项上有指针光标,因为只有它们是可点击的。

After way too much time spent, I finally figured out a solution. 花了太多时间后,我终于找到解决方案。 Here is a jsfiddle , which explains the two lines of code in some detail (in comments). 这是一个jsfiddle ,它详细解释了两行代码(在注释中)。

If you don't understand the details, don't worry about it or just ask me to elaborate. 如果你不了解细节,不要担心它或只是让我详细说明。 :) :)

tl;dr : tl;博士

  1. data: { selection: { enabled: true }, [...]
  2. .c3-bar { cursor: pointer; }

Just use the following CSS 只需使用以下CSS

.c3-bar {
    pointer-events: auto !important;
}

Note that you need the !important to override the inline pointer-events: none that C3 adds to the bars. 请注意,您需要!important来覆盖内联pointer-events: none C3添加到条形图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM