我只是在ng2-nvd3中挣扎着实时更新折线图,我的数据集是好的,但当数据相对到来时,图表没有变化。
请找到解决方案,我们将非常感谢您的帮助。
这是我的Html代码
<nvd3[options]="options"[data] = "data" > </nvd3>这是我的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);
}
}发布于 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库上工作的人可能会发现它很有帮助。
https://stackoverflow.com/questions/44967135
复制相似问题