在函数中使用变量传递给Ng2-nvD3中的对象选项

时间:2017-09-15 20:17:06

标签: angular nvd3.js

有没有选择通过"价值"变量到功能" highlightPoint"在我的例子中:

从@ angular / core';

导入{Component,OnInit}
export class AppComponent implements OnInit {

options;
data;
chartType;
value = 0.9320390859672263;

ngOnInit() {

    this.options = {
        chart: {
            type: 'lineWithFocusChart',
            height: 450,
            margin: {
                top: 20,
                right: 20,
                bottom: 40,
                left: 65
            },
            x: function (d) { return d.x; },
            y: function (d) { return d.y; },
            // useInteractiveGuideline: true,
            xAxis: {
                axisLabel: 'Time (ms)'
            },
            yAxis: {
                axisLabel: 'Voltage (v)',
                tickFormat: function (d) {
                    return d3.format('.02f')(d);
                },
                axisLabelDistance: 5
            },
            dispatch: {},
        }
    };

    this.data = this.sinAndCos();
    this.options.chart.dispatch.renderEnd = this.highlightPoint;

}

highlightPoint() {
    var data = d3.select('svg').datum();

    var points = d3.selectAll('.nv-groups .nv-point');
    debugger
    var filteredPoints = points[0].filter(x => x.__data__[0].y > this.value);
    for (var i = 0; i < filteredPoints.length; i++) {
        var className = filteredPoints[i].className.baseVal.split(" ")[1];
        d3.select("." + className).attr('class', 'nv-point ' + className + ' xyz')
    }
}

}

排队:

var filteredPoints = points[0].filter(x => x.__data__[0].y > this.value);

我需要使用此函数外部的值。有没有任何食谱可以做到这一点? &#34; THIS.VALUE&#34;遗憾的是,没有工作

http://plnkr.co/edit/LP8a0oAhkIsDBYLvpKhT?p=preview

0 个答案:

没有答案