Created
March 3, 2016 09:18
-
-
Save alexey-sh/a269a2ebd41758d362bf to your computer and use it in GitHub Desktop.
alfabank currencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadScript () { | |
return $.getScript('https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js'); | |
} | |
function loadData () { | |
return $.getJSON('https://alfabank.ru/ext-json/0.2/exchange/cash/?offset=0&limit=20').then(function (d) { return d.response.data.usd.filter(function (x) {return x.type==='buy'}); }); | |
} | |
function drawChart () { | |
$.when(loadData(), loadScript()).then(function (currencies) { | |
var table = $('.currency-root'); | |
var canvas = $('<canvas>'); | |
canvas.css({ | |
width: table.width() + 'px', | |
height: table.width() / 2 + 'px', | |
display: 'block', | |
margin: '1em auto' | |
}) | |
table.after(canvas); | |
var data = { | |
labels: currencies.map(function (x){return x.date}).reverse(), | |
datasets: [ | |
{ | |
label: "", | |
fillColor: "rgba(220,220,220,0.2)", | |
strokeColor: "rgba(220,220,220,1)", | |
pointColor: "rgba(220,220,220,1)", | |
pointStrokeColor: "#fff", | |
pointHighlightFill: "#fff", | |
pointHighlightStroke: "rgba(220,220,220,1)", | |
data: currencies.map(function (x){return x.value}).reverse() | |
} | |
] | |
}; | |
var chat = new Chart(canvas.get(0).getContext("2d")).Line(data); | |
}); | |
} | |
if (location.href === 'https://alfabank.ru/omsk/currency/') { | |
drawChart(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment