var colorIndex = 0;
function nextAccentColor(idx)
{
    if(typeof idx === 'undefined') idx = colorIndex++;
    return new $.zui.Color({h: idx * 67 % 360, s: 0.5, l: 0.55});
}

$(document).ready(function()
{
    $("#menu .nav a[href*=" + config.currentMethod + "]").parent().addClass('active');
    $('#menu .nav a[href*=export2Excel]').addClass('iframe');

    var labels   = [];
    var datasets = [];
    var $table   = $('.table-chart');

    $table.find('tbody > tr').each(function(){labels.push($(this).find('.chart-label').text());});

    $table.find('thead > tr > th').not(':first').each(function(idx)
    {
        var color  = nextAccentColor().toCssStr();
        var dataset = {label: $(this).text(), color: color, data: []};
        $table.find('tbody > tr').each(function(){dataset.data.push(parseFloat($(this).find('.chart-value').eq(idx).text()));})
        datasets.push(dataset);

        $(this).find('.chart-color-dot').css('color', color);
    })
    
    var data = {labels: labels, datasets: datasets};
    
    var options = {multiTooltipTemplate: "<%= datasetLabel %> <%= value %>", barDatasetSpacing: 10};
    chart = $('#chart-income').barChart(data, options);
})
