-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
148 lines (129 loc) · 5.22 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Stock Visualization</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
/* Set the container for the canvas to align them side by side */
/* align the chart-container divs to the center of the screen, with some vertical margin */
.chart-container {
display: inline-block;
margin: 20px;
}
canvas {
width: 100% !important;
}
.form-container {
display: inline-block;
margin: 40px;
vertical-align: top;
}
</style>
</head>
<body>
<div>
<h1>Stock Metrics Visualization</h1>
<label for="ticker-select">Select a Stock Ticker:</label>
<select id="ticker-select">
<option value="" disabled selected>Select a ticker</option>
{% for ticker in tickers %}
<option value="{{ ticker }}">{{ ticker }}</option>
{% endfor %}
</select>
</div>
<div class="chart-container">
<canvas id="revenue-chart" width="800" height="400"></canvas>
</div>
<div class="chart-container">
<canvas id="income-chart" width="800" height="400"></canvas>
</div>
<div class="chart-container">
<canvas id="eps-chart" width="800" height="400"></canvas>
</div>
<div class="form-container">
Don't see the ticker you're looking for? Add it here:
<input type="text" id="new-ticker-symbol" placeholder="Enter new ticker symbol"><button onclick="submitNewTicker()">Submit Ticker</button>
</div>
<script>
const tickerSelect = document.getElementById('ticker-select');
const revenueChart = createChart('revenue-chart', 'Revenue', 'Revenue ($ in millions)', 'rgb(100, 99, 132)');
const incomeChart = createChart('income-chart', 'Income', 'Income ($ in millions)', 'rgb(54, 162, 235)');
const epsChart = createChart('eps-chart', 'EPS', 'Earning Per Share (in $)', 'rgb(255, 205, 86)');
function createChart(canvasId, name, y_label, color='rgb(75, 192, 192)') {
return new Chart(document.getElementById(canvasId), {
type: 'line',
data: {
labels: [],
datasets: [{
label: name,
data: [],
fill: false,
borderColor: color,
tension: 0.1
}]
},
options: {
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: y_label,
font: {
size: 14,
lineHeight: 1.2,
},
padding: {top: 20, left: 0, right: 0, bottom: 20}
}
},
x: {
title: {
display: true,
text: 'Year',
font: {
size: 14,
lineHeight: 1.2,
},
padding: {top: 20, left: 0, right: 0, bottom: 20}
}
}
}
}
});
}
function submitNewTicker() {
const tickerSymbol = document.getElementById('new-ticker-symbol').value;
fetch('/add_ticker', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ ticker: tickerSymbol })
})
.then(response => response.json())
.then(data => {
alert('Request submitted successfully! Ticker will be added soon, check back in a few hours!');
})
.catch(error => console.error('Error adding ticker:', error));
}
tickerSelect.addEventListener('change', function() {
const ticker = this.value;
fetch(`/data/${ticker}`)
.then(response => response.json())
.then((data) => {
revenueChart.data.labels = data.revenue.labels;
revenueChart.data.datasets[0].data = data.revenue.data;
incomeChart.data.labels = data.income.labels;
incomeChart.data.datasets[0].data = data.income.data;
epsChart.data.labels = data.eps.labels;
epsChart.data.datasets[0].data = data.eps.data;
revenueChart.update();
incomeChart.update();
epsChart.update();
})
.catch(error => console.error('Error fetching data:', error));
});
</script>
</body>
</html>