Link to home
Start Free TrialLog in
Avatar of clintnash
clintnashFlag for United States of America

asked on

Accessing data in JSON response.d multiple objects

I am trying to populate a chart with data retrieved from SQL.  Using the following code I am able to access the first object d(0)

This all works for the first row (object) but I realized I have no idea how to get the additional rows and all attempts have failed.
 
function OnSuccess(response) {

        var weekDay = response.d[0].DayofWeek;
        var sName = response.d[0].ShortName;
        var loutput = response.d[0].List_Output;

        //roated chart
        c3.generate({
            bindto: '#roated-chart',
            data: {
                columns: [
                ['Weekday', loutput]

                ],
                names: {
                    Weekday: 'Requested Practice',
                    data2: 'Data Name 2',
                },
                types: {
                    Weekday: 'bar',
                    labels: true
                },
                colors: {
                    Weekday: '#0b62a4'

                },
            },
            axis: {
                rotated: true,
                x: {
                    type: 'categorized',
                    categories: [sName]
                }
            }
        });
    };

Open in new window


The objects includes 7 rows (one for each day of the week). My working example above shows Monday.

Any help or advise is greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clintnash

ASKER

Thank you, your solution showed only the last row of data however you pointed me in the correct direction. Changing the for loop to the following resolved it all.

<code> for (var i=0; i<response.d.length; i++) {
         
            sName.push(response.d[i].ShortName);
            loutput.push(response.d[i].List_Output);
           
        }
</code>

Thanks again!!!