C3: Onclick isn't working for pie charts in C3 version 0.5.1

Created on 27 Mar 2018  路  10Comments  路  Source: c3js/c3

  • C3 version:v0.5.1
  • D3 version:4.13.0
  • Browser:Chrome
  • OS:MacOS

When using utilizing Pie Charts, the behavior seems to have changed. Currently, onclick, mouseover, and mouseout events added to the data element are not working. It also isn't working in the example at http://c3js.org/samples/chart_pie.html.

code snippet:

data:{
columns: data,
type: 'pie',
onclick:function(d,element){
console.log("Clicked");
}
}

Most helpful comment

I found a work around in the meantime. Add the following to your css:

.c3-event-rects {
   display: none;
}

one of the shapes was blocking the events from firing since it's stacked on top of the other shapes that make your donut/pie chart. I haven't encountered any errors with this solution yet, but I will update if I do.

All 10 comments

+1
v0.5.0 seem to have broke pie, donut and gauge charts. Even default events like highlight on hover not working.

any update on this issue? Have the same problem on gauge chart.

does anyone know what version onclick for donut and pie isn't broken?

I found a work around in the meantime. Add the following to your css:

.c3-event-rects {
   display: none;
}

one of the shapes was blocking the events from firing since it's stacked on top of the other shapes that make your donut/pie chart. I haven't encountered any errors with this solution yet, but I will update if I do.

Having the same problem in C3 0.5.4, and you can see the bug here: http://c3js.org/samples/chart_donut.html

@ecupaio's solution is working for me on a pie chart, but not a bar chart.

The real problem seems to be that .c3-event-rects is rendered as the last DOM node, when it should be the first. For example, on the donut chart demo linked above, if you use the Chrome debugger to reorder the nodes from this

screen shot 2018-04-27 at 5 00 47 pm

To this

screen shot 2018-04-27 at 5 01 03 pm

Mouse events will work again.

It seems like this is how the DOM nodes were ordered in v0.4.22 of C3, before we noticed this bug occurring.

Having the same problem in C3 0.6.1

2391

2391

2354

Closing as duplicate of #2354

Was this page helpful?
0 / 5 - 0 ratings