0

Not sure what I'm missing below but would like to push some item lists into this array in this format below:

stackedByYear = new Array(
            [[14,44],'2007'],
            [[18,38],'2008'],
            [[4.5,22],'2009']        
        );

I tried the below but not working

var stackedByYear= function() {
 var listName = "Budget_Vs_Actual";
    var url = _spPageContextInfo.webAbsoluteUrl;     
    getListItems(listName, url, function (data) {       
        var array = new Array();
        var items = data.d.results;              
        var html = "";
        // Add all the new items
        for (var i = 0; i < items.length; i++) {
            //alert(items[i].Title + ":" + items[i].Actual + "" + items[i].Budget);
           //array.push(3,4,'wew');
          array.push([items[i].Actual,items[i].Budget,items[i].Title]);

        }
         return array;    
})
};

I would like to pass the array results to the below

$("#stackedGraph").jqBarGraph({

    data: stackedByYear,

    colors: ['#242424','#437346'],

    legends: ['ads','leads'],

    legend: true,

    width: 500,

    prefix: '$',

    postfix: 'k',

    title: '<h3>Total revenue by year <br /><small>stacked bar graph</small></h3>'

});

1 Answer 1

1

Try changing the body of your for loop to this (notice the double [ ):

array.push([[items[i].Actual,items[i].Budget],items[i].Title]);
1
  • Thanks for that but when i call the stackedByYear in the data: stackedByYear it doesn't work .Do you know what i could be missing?
    – naijacoder
    Feb 17, 2018 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.