首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ng2-nvd3实时折线图更新

ng2-nvd3实时折线图更新
EN

Stack Overflow用户
提问于 2017-07-07 17:21:48
回答 1查看 553关注 0票数 1

我只是在ng2-nvd3中挣扎着实时更新折线图,我的数据集是好的,但当数据相对到来时,图表没有变化。

请找到解决方案,我们将非常感谢您的帮助。

这是我的Html代码

代码语言:javascript
复制
    <nvd3[options]="options"[data] = "data" > </nvd3>

这是我的Javascript代码

代码语言:javascript
复制
export class AppComponent implements OnInit {
    options;
    data;
    chartType;

    ngOnInit() {

        this.options = {
            chart: {
                type: 'lineChart',
                height: 450,
                margin: {
                    top: 20,
                    right: 20,
                    bottom: 40,
                    left: 55
                },
                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: -10
                }
            }
        };

        this.sinAndCos();
    }


    sinAndCos() {
        var sin = [], sin2 = [],
            cos = [];

        //Data is represented as an array of {x,y} pairs.
        for (var i = 0; i < 100; i++) {
            sin.push({ x: i, y: Math.sin(i / 10) });
        }

        //Line chart data should be sent as an array of series objects.
        this.data = [
            {
                values: sin,      //values - represents the array of {x,y} data points
                key: 'Sine Wave', //key  - the name of the series.
                color: '#ff7f0e'  //color - optional: choose your own line color.
            }
        ];

        var x = i;
        setInterval(() => {

            this.data[0].values.push({ x: i, y: Math.sin(i / 10), series: 0 })

            i++;
        }, 500);



    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-06-03 23:16:46

在HTML中,添加config属性。

nvd3options="options“data="data”config="configVariable" >

在javascript文件中,创建配置变量,如下所示: let configVariable ={ refreshDataOnly: true };

有关更多选项,请参阅此处的文档,http://krispo.github.io/angular-nvd3/#/quickstart

我知道这个问题已经提出很长时间了,但我现在回答这个问题,因为上面提到的答案对我很有效,可能目前在这个nvd3库上工作的人可能会发现它很有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44967135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档