aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131/hw6/strap012_hw6/public/stock.html
blob: d63b23323307fb3b7688e110eb49b8ecc0470b56 (plain) (blame)
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
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
      pre {
        max-height: 12em;
      }
      textarea {
          width: 100%;
          min-height: 30rem;
          background-color: black;
          font-family: "Lucida Console", Monaco, monospace;
          font-size: 0.75 rem;
          line-height: 1.2;
          color: #fff;
      }
  </style>
</head>

<body>
  <nav class="navbar navbar-default">
   	<div class="container-fluid">
      <ul class="nav navbar-nav">
          <li><a href="/"><b>Home</b></a></li>
          <li><a href="contacts"><b>Contacts</b></a></li>
          <li><a href="addContact"><b>Add Contact</b></a></li>
          <li><a href="stock"><b>Stock Page</b></a></li>
          <li><a href="logout"><b>Logout</b></a></li>
      </ul>
  	</div>
	</nav>
  <br><br>

  <div class="container">
    <div class="panel panel-default">
      <div class="panel-body"><center>Welcome to Stock Page</center></div>
    </div>
  </div>

  <div class="container">
    <div class="row">
      <div class="col">
        <table class="table table-bordered table-hover">
          <tbody>
            <tr>
              <td class="col-md-6">Company</td>
              <td class="col-md-6">
                <div class="form-group">
                  <select id="Company" name="Company">
                    <option value="GME">Gamestop</option>
                    <option value="MSFT">Microsoft</option>
                    <option value="BA">Boeing Company</option>
                    <option value="AAPL">Apple Inc</option>
                    <option value="AMZN">Amazon</option>
                    <option value="NVDA">NVIDIA Corporation</option>
                  </select>
                </div>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <button type="button" onclick="Click()">Get Data</button>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>

  <div class="container">
      <div id="chartContainer"></div>
  </div>

  <div class="container">
    <table class="table" id="StockData">
      <thead>
        <tr>
          <th scope="col" id="meta">Company-MetaData</th>
          <th scope="col" id="Time">Stock-Info</th>
        </tr>
      </thead>
      <pre>
      <tbody></tbody>
      </pre>
    </table>
  </div>

  <script>
    function Click() {
      var comp = document.getElementById("Company").value;
      var xmlhttp = new XMLHttpRequest();
      var url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + comp + "&apikey=8MWSNPDWKH0BTBH2";
      xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
          var parse = JSON.parse(xmlhttp.responseText);
          var table = document.getElementById("StockData").getElementsByTagName("tbody")[0];
          var row = table.insertRow();
          for (var i in parse) {
            var cell = row.insertCell();
            cell.innerHTML = "<pre>" + JSON.stringify(parse[i], undefined, 2) + "</pre>";
          }
        }
      }
      xmlhttp.open("GET", url, true);
      xmlhttp.send();

    }
   /* TODO:
   /    Bonus 1. Request the TIME_SERIES_DAILY endpoint of alphavantage API
   /             for the company selected in the dropdown. Display the JSON
   /             in the result according to the write up.
   /    Bonus 2. Take the JSON from the alphavantage API and chart it to a
   /             line chart using Chart.js to the chartContainer div. Ensure
   /             the chart meets all requirements from the HW writeup.
   /*/
  </script>
</body>
</html>