File: shareprice.html

package info (click to toggle)
jsxgraph 1.3.5%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 26,044 kB
  • sloc: xml: 5,869; java: 1,072; python: 747; php: 192; makefile: 146; sh: 47
file content (75 lines) | stat: -rw-r--r-- 2,631 bytes parent folder | download | duplicates (5)
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
<html>
<head>
   <title>JSXGraph example: YahooFinance server module</title>
   <link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" />
   <script type="text/javascript" src="../distrib/jquery.min.js"></script>
   <script type="text/javascript" src="../src/loadjsxgraph.js"></script>
</head>
<body>
<h2>Get shareprices with YahooFinance server module</h2>
In case there's no internet connection goto <a href="fakeshareprice.html">fake data</a> example.<br />
<select id="stock"><option value="^GDAXI">DAX</option><option value="^DJI">Dow Jones</option></select>
<a href="#" onclick="change();">Load this stock quote</a>
<div style="width:800px">
  <div id="jxgbox" class="jxgbox" style="width:600px; height:450px; float:left"></div>
</div>
<div id="debug" style="display:block;"></div>
<script type="text/javascript">
/* <![CDATA[ */

    var x = [], y = [], g, board, val, hi, lo, share, timer, restart = true;

    JXG.Server.loadModule('YahooFinance');

    var init = function (data) {
        hi = data.max*1.00002;
        lo = data.min*0.99998;
        board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [0, hi, 200, lo], axis: true, grid: false});
        board.createElement('axis',[[0,lo],[1,lo]]);
    }

    var cb = function (data) {
        try {
            x.push(x.length+1);
            y.push(data.price);
            val = data.price;
            if (restart) {
                restart = false
                g = board.create('curve', [x,y],{strokeWidth:3, strokeColor:'green',shadow:false}); 
                txt = board.create('text', [3,(hi+lo)*0.5,function(){return share + ' = '+val;}],{fontSize:'14px'}); 
                reg = board.create('functiongraph',[JXG.Math.Numerics.regressionPolynomial(1,g.dataX,g.dataY)],{strokecolor:'red',dash:3});
            } else {
                g.dataX = x;                    
                g.dataY = y;
            }
            board.update();
        } catch (e) { $('#debug').html(e); }
    }

    function change() {
        // clean up
        if(board) {
            board.removeObject([g, txt, reg]);
            JXG.JSXGraph.freeBoard(board);
            delete g;
            delete txt;
            delete reg;
            delete board;
        }
        if(timer)
            window.clearInterval(timer);

        share = $('#stock').val();

        restart = true;
        x = [];
        y = [];

        JXG.Server.modules.YahooFinance.getMinMax(share, init);
        timer = window.setInterval('JXG.Server.modules.YahooFinance.getCurrentSharePrice("' + share + '", cb);', 1300);
    }

  /* ]]> */
  </script>
</body>
</html>