ghostcoder
ghostcoder

Reputation: 493

Clickable bars in bar charts if xUnits is not dc.units.ordinal

dc.js allows clickable bar charts only for ordinal values From dc.js:

if (_chart.isOrdinal()) bars.on("click", _chart.onClick);

I tried the following and got Uncaught TypeError: Cannot read property 'isFiltered' of undefined at dc.js

chart.renderlet(function(_chart){ _chart.selectAll("rect.bar").on("click", _chart.onClick); });

https://github.com/dc-js/dc.js/issues/168 suggests to implement custom onClick handler but I am not sure what its content should be.

Upvotes: 1

Views: 451

Answers (1)

Gordon
Gordon

Reputation: 20120

I have been hearing about this error for a while, and finally tracked it down. The advice to use .on("click", _chart.onClick) is generally good, but it got broken by the bar chart's version of onClick becoming private for some reason. (For details, see my comment in the issue cited above.)

Two possible solutions:

  1. Define your renderlet like this (hacky workaround): chart.renderlet(function(_chart){ _chart.selectAll("rect.bar").on("click", function(d) { _chart.onClick(d.data); }); });
  2. Update to dc.js 2.0.0-beta.4, where this is fixed and the original code you posted should work.

Upvotes: 2

Related Questions