srthu srthu - 1 year ago 123
AngularJS Question

Programmatically updating brush for LineWithFocusChart in Angular nvd3

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?

Answer Source

The dispatch function for brush changes can be as follows:

function (e) {
    $timeout(function () {
        $[e.extent[0], e.extent[1])
    }, 400)

$ 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download