C3: Disable legend clicking option

Created on 12 Aug 2014  路  9Comments  路  Source: c3js/c3

Clicking the legends to show or hide the data in the graph is great -- mostly. It's terrible when there's just one, for example. It would be great if there was an option to disable that when there's only one.

question resolved maybe

Most helpful comment

@masayuki0812 your solution overwrites the onclick function, but I still think it's misleading that the user can click the legend and the cursor changes on hover. An option to disable the onclick for legends would be great

All 9 comments

I had to use the 'Hide Legend' option. It's not the best thing to do, but assuming that the legend in such cases is not that important it was fine by me. http://c3js.org/samples/options_legend.html

Thanks! I noticed that, but unfortunately I needed to display the legend.

Hi, please try legend.item.onclick = function () {}. Actually, an option to disable seems natural, but this solution can work.

It seems working, so please let me close.

@masayuki0812 your solution overwrites the onclick function, but I still think it's misleading that the user can click the legend and the cursor changes on hover. An option to disable the onclick for legends would be great

IMHO this is still a problem.
A workaround, is to use CSS to hide the button

.c3-legend-item {
  display: none;
}

This would be better

    .c3-legend-item {
        cursor:default !important;
    }

.c3-legend-item
{
pointer-events: none;
}

Ended up doing a combination of the comments. Hovering on the legend still works, and clicking wont do anything, as well as the cursor pointer.

chart init:

c3.generate({
  ...
  legend: {
    item: { onclick: function () {} }
  }
});  

css:

.c3-legend-item {
  cursor:default !important;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarcusJT picture MarcusJT  路  4Comments

u119102 picture u119102  路  3Comments

jstone-ponderosa picture jstone-ponderosa  路  3Comments

seubert picture seubert  路  3Comments

alantygel picture alantygel  路  3Comments