convert json response to an array which can be used for d3 funnel chart

example json:

{
    "json_data": [
        {
            "budget": 1000,
            "Actual": "3468.000 "
        },
        {
            "budget": 2000,
            "Actual": "7905.000 "
        },
        {
            "budget": 3000,
            "Actual": "7454.000 "
        },
        {
            "budget": 4000,
            "Actual": "3671.000 "
        },
        {
            "budget": 5000,
            "Actual": "5875.000 "
        },
        {
            "budget": 6000,
            "Actual": "6157.000 "
        },
        {
            "budget": 7000,
            "Actual": "7520.000 "
        },
        {
            "budget": 8000,
            "Actual": "2251.000 "
        },
        {
            "budget": 9000,
            "Actual": ""
        },
        {
            "budget": 10000,
            "Actual": ""
        },
        {
            "budget": 11000,
            "Actual": ""
        },
        {
            "budget": 12000,
            "Actual": ""
        }
    ]
}

to ARRAY OF THIS FORMAT:

vardata=[
    [
        'VideoViews',
        1500
    ],
    [
        'Comments',
        1000
    ],
    [
        'VideoResponses',
        900
    ],
    [
        'VideoViews',
        1500
    ],
    [
        'Comments',
        1000
    ],
    [
        'VideoResponses',
        900
    ]
];

Answers


This is how i might do it. In short, you are trying to convert an array of object to an array of array.

output = [] // this will become  an array of array

// assuming json_data is store in example    

for (var i=0;i< (example['json_data']).length;i++){
    var entry = exmple['json_data'][i] 
    output.push(['budget', entry['budget']]);
    output.push(['Actual',entry['Actual']]);

}

console.log(JSON.stringify(output))
// [["budget",1000],["Actual","3468.000 "],["budget",2000],\
// ["Actual","7905.000 "],["budget",3000] ... ] // 

Need Your Help

using Regular Expression how to get (16.00 + 28.66 = 44.66) as 44.66 and (99) as 99

c# asp.net regex

Im using regular expression to get values such as (16.00 + 28.66 = 44.66) as 44.66 ,(26.00) as 26.00

Fixed nav bar on mobile

html css twitter-bootstrap

Hey I did implement a fixed nav bar (that stays at the top of the page while you scroll down the page) using bootstrap.