|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <div class="tile is-ancestor"> |
| 4 | + <div class="tile is-parent is-8"> |
| 5 | + <article class="tile is-child box"> |
| 6 | + <p class="title control" :class="{'is-loading': isloading}"> |
| 7 | + Price History of {{params.symbol}} |
| 8 | + <span class="subtitle help is-danger is-5"> |
| 9 | + This demo only works under Development env |
| 10 | + </span> |
| 11 | + </p> |
| 12 | + <chart :type="'line'" :data="stockData" :options="options"></chart> |
| 13 | + </article> |
| 14 | + </div> |
| 15 | + <div class="tile is-parent is-4"> |
| 16 | + <article class="tile is-child box"> |
| 17 | + <div class="block"> |
| 18 | + <p class="title is-5">Request Params</p> |
| 19 | + <a href="https://github.com/markitondemand/DataApis" class="link">Markit On Demand - Market Data APIs</a> |
| 20 | + </div> |
| 21 | + <div class="block"> |
| 22 | + <div class="control is-horizontal"> |
| 23 | + <div class="control-label"> |
| 24 | + <label class="label">Symbol</label> |
| 25 | + </div> |
| 26 | + <div class="control"> |
| 27 | + <div class="select is-fullwidth"> |
| 28 | + <select v-model="params.symbol"> |
| 29 | + <option v-for="s in symbols" :value="s">{{s}}</option> |
| 30 | + </select> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + <div class="control is-horizontal"> |
| 35 | + <div class="control-label"> |
| 36 | + <label class="label">Days</label> |
| 37 | + </div> |
| 38 | + <div class="control is-fullwidth"> |
| 39 | + <input class="input" min="0" max="720" type="number" v-model="params.numberOfDays"> |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + <div class="control is-horizontal"> |
| 43 | + <div class="control-label"> |
| 44 | + <label class="label">Period</label> |
| 45 | + </div> |
| 46 | + <div class="control"> |
| 47 | + <div class="select is-fullwidth"> |
| 48 | + <select v-model="params.dataPeriod"> |
| 49 | + <option v-for="p in periods" :value="p">{{p}}</option> |
| 50 | + </select> |
| 51 | + </div> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + <div class="control is-horizontal"> |
| 55 | + <div class="control-label"> |
| 56 | + <label class="label"></label> |
| 57 | + </div> |
| 58 | + <div class="control"> |
| 59 | + <button class="button is-primary" :class="{'is-loading': isloading}" @click="loadData">Refresh</button> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + </article> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | +</template> |
| 68 | + |
| 69 | +<script> |
| 70 | +import Chart from 'vue-bulma-chartjs' |
| 71 | +
|
| 72 | +const api = '/MODApis/Api/v2/InteractiveChart/json' |
| 73 | +
|
| 74 | +export default { |
| 75 | + components: { |
| 76 | + Chart |
| 77 | + }, |
| 78 | +
|
| 79 | + data () { |
| 80 | + return { |
| 81 | + params: { |
| 82 | + symbol: 'AAPL', |
| 83 | + numberOfDays: 450, |
| 84 | + dataPeriod: 'Month' |
| 85 | + }, |
| 86 | + symbols: ['AAPL', 'MSFT', 'JNJ', 'GOOG'], |
| 87 | + periods: ['Day', 'Week', 'Month', 'Quarter', 'Year'], |
| 88 | + data: [], |
| 89 | + labels: [], |
| 90 | + isloading: false, |
| 91 | + options: { |
| 92 | + legend: { display: false }, |
| 93 | + animation: { duration: 0 }, |
| 94 | + scales: { |
| 95 | + xAxes: [{ |
| 96 | + type: 'time', |
| 97 | + time: { |
| 98 | + unit: 'month' |
| 99 | + } |
| 100 | + }] |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + }, |
| 105 | +
|
| 106 | + computed: { |
| 107 | + stockData () { |
| 108 | + return { |
| 109 | + labels: this.labels, |
| 110 | + datasets: [{ |
| 111 | + fill: false, |
| 112 | + lineTension: 0.25, |
| 113 | + data: this.data, |
| 114 | + label: 'Close price', |
| 115 | + pointBackgroundColor: '#1fc8db', |
| 116 | + pointBorderWidth: 1 |
| 117 | + }] |
| 118 | + } |
| 119 | + } |
| 120 | + }, |
| 121 | +
|
| 122 | + methods: { |
| 123 | + loadData () { |
| 124 | + this.isloading = true |
| 125 | + this.labels.length = 0 |
| 126 | + this.data.length = 0 |
| 127 | + this.$http({ |
| 128 | + url: api, |
| 129 | + transformResponse: [(data) => { |
| 130 | + return JSON.parse(data.replace(/T00:00:00/g, '')) |
| 131 | + }], |
| 132 | + params: { |
| 133 | + parameters: { |
| 134 | + 'Normalized': false, |
| 135 | + 'NumberOfDays': parseInt(this.params.numberOfDays), |
| 136 | + 'DataPeriod': this.params.dataPeriod, |
| 137 | + 'Elements': [{'Symbol': this.params.symbol, 'Type': 'price', 'Params': ['c']}] |
| 138 | + } |
| 139 | + } |
| 140 | + }).then((response) => { |
| 141 | + let dates = response.data.Dates |
| 142 | + let price = response.data.Elements[0].DataSeries.close.values |
| 143 | + this.data.push(...price) |
| 144 | + this.labels.push(...dates) |
| 145 | + this.isloading = false |
| 146 | + }).catch((error) => { |
| 147 | + console.log(error) |
| 148 | + }) |
| 149 | + } |
| 150 | + } |
| 151 | +} |
| 152 | +</script> |
| 153 | + |
| 154 | +<style scoped> |
| 155 | +</style> |
0 commit comments