krispo / ng2-nvd3

Angular2 component for nvd3
http://krispo.github.io/ng2-nvd3/
MIT License
328 stars 104 forks source link

adding an event/callback on mouse clicks #35

Open daftster opened 8 years ago

daftster commented 8 years ago

Hi,

How do I add an event/callback for mouse clicks? I've tried adding dispatch and would see the console logs inside the functions, but unable it is unable to see my component variables.

In the code below, i could see console logging, but the setting of displayData is not done. I've also tried calling a function inside dispatch, but the browser says it is undefined. What I want to is to be able to call my own function on a mouse click event. displayData: string = "abc"; ngOnInit(){ this.options = { chart: { type: 'historicalBarChart', height: 70, color: ["#2BBED8"], margin : { top: 0, right: 10, bottom: 10, left: 10 }, dispatch: { //container of event handlers elementMousemove: function(e){ console.log("mousemove"+ JSON.stringify(e)); this.displayData = "xyz" }, elementMouseout: function(e){ console.log('mouseout'+ JSON.stringify(e)) }, chartClick: function(e){ this.displayData = "xyz"; console.log('chartClick'+ JSON.stringify(e)) }, elementClick: function(e){ console.log('elementClick'+ JSON.stringify(e)) }, elementDblclick: function(e){ console.log('double click' + JSON.stringify(e)) } },

Thanks,

daftster commented 8 years ago

I think we're having the same issue here... http://stackoverflow.com/questions/38392390/bind-ng2-nvd3-chart-with-component-in-angular-2-using-dispatch