Skip to content

Instantly share code, notes, and snippets.

@brunchybit
Created August 1, 2014 18:58
Show Gist options
  • Save brunchybit/1bb7e818fe888c562ec1 to your computer and use it in GitHub Desktop.
Save brunchybit/1bb7e818fe888c562ec1 to your computer and use it in GitHub Desktop.
Dispatchination
nv.addGraph(function() {
var chart = nv.models.stackedAreaChart()
.x(function(d) { return d[0]})
.y(function(d) { return d[1]})
// axis stuff
chart.xAxis //...
chart.yAxis //...
function override_clicks() {
// if you have a stacked area chart, the overrides you want to dispatch are as follows
chart. stacked.dispatch.on("areaClick", function(hadouken) { console.log(hadouken);}) // hadouken will give you the element you clicked on
chart.stacked.dispatch.on("areaClick.toggle", function(shinjuken) { });
// bar charts are similar
chart.multibar.dispatch.on("elementClick", function(e) { console.log(e)});
// you can even override legend clicks with these dudes
// of course returning null will just disable whatever you're working with.
chart.legend.dispatch.on("legendClick", null);
chart.legend.dispatch.on("legendDblClick", null);
chart.legend.dispatch.on("stateChange", null);
// the only tricky bit is making sure your changes are preserved after an update on the chart itself (real time or window resize, etc)
if(chart.update) {
var og_update = chart.update;
chart.update = function() {
og_update();
override_clicks();
}
}
override_clicks();
nv.utils.windowResize(chart.update);
return chart;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment