window.onload = function() {
// init chart
initChart();
};
// VK app
VK.init({
apiId: 5225204
});
function getMembers(gid, callback) {
VK.Api.call('groups.getById', {group_id: gid, fields: 'members_count'}, function(data){
if(data.response) {
console.log('success');
console.log(data.response[0].members_count);
callback(data.response[0].members_count);
} else {
console.log('error');
}
});
}
// get groups members
getMembers('group1', function(gr1) {
getMembers('group2', function(gr2) {
getMembers('group3', function(gr3) {
getMembers('group4', function(gr4) {
// draw chart
var chartData = [gr1, gr2, gr3, gr4];
});
});
});
});// var chartData = [343, 123, 432, 963]; // test chart
var canvas, ctx;
function initChart() {
canvas = document.getElementById('chart');
ctx = canvas.getContext('2d');
drawChart(80, 370);
}
function drawChart(x, y) {
ctx.fillStyle='orangered';
for (var i = 0; i < chartData.length; i++) {
ctx.fillRect(x + i * 100, y, 60, chartData[i] / -10);
}
}