G

Untitled

public
Guest May 02, 2024 Never 13
Clone
Plaintext paste1.txt 107 lines (96 loc) | 2.64 KB
1
// initializeChart(){
2
// const chart2 = Highcharts.chart('init',{
3
// chart:{
4
// zooming:{
5
// type:"xy"
6
// }
7
// },
8
// time:{
9
// timezone:'Asia/Kolkata'
10
// },
11
// title:{
12
// text:'Random Data'
13
// },
14
// xAxis:{
15
// type:'datetime',
16
// tickPixelInterval : 150
17
// },
18
// yAxis:{
19
// title:{
20
// text:'Value'
21
// }
22
// },
23
// series:[{
24
// type:'spline',
25
// name:'Random data',
26
// data: []
27
// }
28
// ]
29
// });
30
31
// setInterval(()=>{
32
// const x = (new Date()).getTime()
33
// const y = Math.trunc(Math.random()*100);
34
// chart2.series[0].addPoint([x,y], true, true)
35
// }, 1000)
36
37
38
// this.addInitialDataPoints(chart2);
39
// }
40
41
// generateInitialData():[number, number][]{
42
// const initData :[number, number][] = [];
43
// const now = (new Date()).getTime()
44
// for(let i=10; i>=0; i--){
45
// initData.push([now-i*1000, Math.trunc(Math.random()*100)]);
46
// }
47
// return initData;
48
// }
49
50
// addInitialDataPoints(chart: Highcharts.Chart): void {
51
// const now = (new Date()).getTime();
52
// for (let i = 0; i < 10; i++) {
53
// const x = now - (10 - i) * 1000;
54
// const y = Math.trunc(Math.random() * 100);
55
// setTimeout(() => {
56
// chart.series[0].addPoint([x, y], true, i === 9);
57
// }, i * 1000);
58
// }
59
// }
60
61
62
initializeChart(): void {
63
const chart2 = Highcharts.chart('init', {
64
chart: {
65
type: 'spline'
66
},
67
title: {
68
text: 'Random Data'
69
},
70
xAxis: {
71
type: 'datetime',
72
tickPixelInterval: 150
73
},
74
yAxis: {
75
title: {
76
text: 'Value'
77
}
78
},
79
series: [{
80
type: 'spline',
81
name: 'Random data',
82
data: []
83
}]
84
});
85
86
// Add initial data point
87
this.addInitialDataPoint(chart2);
88
89
// Update chart with new data points every second
90
setInterval(() => {
91
this.addNewDataPoint(chart2);
92
}, 1000);
93
}
94
95
addInitialDataPoint(chart: Highcharts.Chart): void {
96
const now = (new Date()).getTime();
97
const x = now;
98
const y = Math.trunc(Math.random() * 100);
99
chart.series[0].addPoint([x, y], true);
100
}
101
102
addNewDataPoint(chart: Highcharts.Chart): void {
103
const now = (new Date()).getTime();
104
const x = now;
105
const y = Math.trunc(Math.random() * 100);
106
chart.series[0].addPoint([x, y], true, chart.series[0].data.length >= 10); // Shift if data length exceeds 10 points
107
}