Skip to content

Instantly share code, notes, and snippets.

@alexey-sh
Created March 3, 2016 09:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexey-sh/a269a2ebd41758d362bf to your computer and use it in GitHub Desktop.
Save alexey-sh/a269a2ebd41758d362bf to your computer and use it in GitHub Desktop.
alfabank currencies
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