-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.component.html
155 lines (133 loc) · 3.84 KB
/
time.component.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/amstock.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.23/moment-timezone-with-data-2012-2022.min.js"></script>
<div id="chartdiv"></div>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
#chartdiv {
width: 100%;
height: 300px;
}
</style>
<div id="chartdiv"></div>
<script>
/**
* function that generates random data for preset period/granularity
* @days days to generate data for
* #granularity in minutes
*/
function generateData(days, granularity) {
// init return array
var data = [];
// add a first empty data point 2 years back
// var firstDate = new Date();
// firstDate.setFullYear(firstDate.getFullYear() - 2);
// firstDate.setHours(0, 0, 0, 0);
// data.push({
// date: firstDate
// });
// add data points
var now = new Date();
var date = new Date();
date.setDate(date.getDate() - days);
date.setHours(0, 0, 0, 0);
while (date.getTime() <= now.getTime()) {
date.setTime(date.getTime() + (granularity * 60000));
var curDate = new Date(date);
data.push({
date: curDate,
value: (Math.round(Math.random() * 40) + 100)
});
}
console.log(data);
return data;
}
/**
* Create the chart
*/
var chart = AmCharts.makeChart("chartdiv", {
type: "stock",
dataSets: [{
title: "2 days | granularity: 1 min.",
color: "#F60",
fieldMappings: [{
fromField: "value",
toField: "value"
}],
dataProvider: generateData(2, 1),
categoryField: "date"
}],
panels: [{
stockGraphs: [{
id: "g1",
valueField: "value",
comparable: true,
compareField: "value",
balloonText: "[[title]]:<b>[[value]]</b>"
}],
stockLegend: {
periodValueTextRegular: "[[value.close]]"
}
}],
chartScrollbarSettings: {
graph: "g1"
},
categoryAxesSettings: {
minPeriod: "mm",
maxSeries: 500
},
chartCursorSettings: {
valueBalloonsEnabled: true,
fullWidth: true,
cursorAlpha: 0.1,
valueLineBalloonEnabled: true,
valueLineEnabled: true,
valueLineAlpha: 0.5
},
periodSelector: {
// periods: [ {
// period: "DD",
// selected: true,
// count: 1,
// }, ]
},
});
/**
* Add event handlers to catch zoom events
* We're adding zoomed events after the chart is rendered
*/
chart.addListener("rendered", function() {
chart.ignoreZoom = true;
chart.addListener("zoomed", function(event) {
// ignore this zoom?
if (chart.ignoreZoom) {
chart.ignoreZoom = false;
return;
}
// check the first date
var now = new Date();
var days = (now.getTime() - event.startDate.getTime()) / 86400000;
// figure out which data set to use
var dataSet;
if ( days <= 2 )
dataSet = chart.dataSets[0];
else if ( days <= 10 )
dataSet = chart.dataSets[1];
else
dataSet = chart.dataSets[2];
// check if this data set is already set
if ( chart.mainDataSet === dataSet )
return;
// change the data set
chart.mainDataSet = dataSet;
chart.ignoreZoom = true;
chart.validateNow(false, true);
});
});
</script>