0

I am using the "LineWithFocusChart" in the Angular-nvd3 directives. The link to this directive is here

Now I need to change the focus of this chart programmatically rather than using the focus chart below. The answer for this issue is in this stackoverflow question for the case of a simple nvd3 element. But I need to implement the same in the Angular directive of this chart.

I went through the docs and the issues on GitHub but to no avail. Can someone please help?

Community
  • 1
  • 1
srthu
  • 197
  • 2
  • 14

1 Answers1

1

The dispatch function for brush changes can be as follows:

function (e) {
    $timeout(function () {
        $scope.tc.api.getScope().chart.brushExtent([e.extent[0], e.extent[1])
    }, 400)
}

$scope.tc.api represents the api for the other chart you wish to manipulate. It needs to be added to the chart directive as 'api="tc.api"' and declared in the controller before it can be manipulated.

The timeout is important because the directive needs a bit of time before it is loaded and its API gets activated.

EDIT 1 @ackuser has kindly set up a plunkr for the solution. http://plnkr.co/edit/0je3AsF0wdjkFWUyvl02?p=preview

Valera Tumash
  • 628
  • 7
  • 16
srthu
  • 197
  • 2
  • 14
  • Hi, Can you put a plnkr or jsfiddle with your solution...I think your question is really interesting – ackuser Nov 13 '15 at 11:42
  • Sure. I actually don't know how to create a plnkr. I will put one up in 1-2 days. – srthu Nov 14 '15 at 12:14
  • @ Srujan Routhu .. Did you do this? I can create the plunkr for you if you need – ackuser Nov 22 '15 at 11:26
  • Hey. It seems like you've done it all yourself. It's working exactly as expected, wherein the brush is auto adjusting after a little time. For more integrity, you can put the timeout function inside the callback function of the chart. This way, even if the chart api loads late the brush adjustment will execute – srthu Nov 25 '15 at 07:03
  • hehe ok so pls give me a point ;)....It because I have done it weeks ago so I didn't even remember I solved the problem – ackuser Nov 25 '15 at 10:40
  • The plunkr doesn't work I think - would you be so kind to update it? I still don't get how you managed to make that work. – user3255061 Dec 16 '15 at 10:19
  • 1
    I updated the Plunkr so now it is working. I wasn't able to make it working without adding api.update() after the brush extent domain is changed. – Valera Tumash Aug 12 '16 at 04:28