jquery - Convert JavaScript Object to JSON String for Key and Values -


i working on building web application client , close being done, have few hang ups need little bit of with.

i need of turning javascript object's keys , values json string can use in chart. chart using chartjs.

this array looks like.

object {full-time: object, part-time: object}      full-time: object         access: 1         excel: 2         facebook: 1         nosql: 1         php: 1         webex: 1         wordpress: 1     part-time: object         .net: 1         adobe photoshop: 1         visual basic: 1         wordpress: 1         xml: 1 

my ultimate goal have couple variables when run through $.each on main object have in code this:

 skillgraph[key]['labels'] = here (.push ??)  

then when console log each of variable this:

 skillgraph['part-time']['labels'] = [".net","adobe photoshop", "visual basic","wordpress", "xml"]  skillgraph['part-time']['values'] = [1,1,1,1,1] 

that way can call chartjs graph this:

var workertypept = {     labels : skillgraph['part-time']['labels'],     datasets : [                     {             fillcolor : "rgba(151,187,205,0.5)",                             highlightfill : "rgba(151,187,205,0.75)",             data: skillgraph['part-time']['values']          }     ] } 

what have tried?

i have tried doing $.each on main object , doing $.each on key of here current code. inside {{ }} see in console first iteration.

graphworkertype = {};  $.each(skillcountpertype, function(key, value) {     console.log(key); {         {             full - time         }     }     console.log(value); {         {             object {                 php: 1,                 nosql: 1,                 webex: 1,                 facebook: 1,                 wordpress: 1…             }             access: 1             excel: 2             facebook: 1             nosql: 1             php: 1             webex: 1             wordpress: 1         }     }      $('#typeuser').append('<option value="' + key + '">' + key + '</option>');      skillsforgraph = json.stringify(skillcountpertype[value]);     console.log(skillsforgraph); {         {             {                 "php": 1,                 "nosql": 1,                 "webex": 1,                 "facebook": 1,                 "wordpress": 1,                 "excel": 2,                 "access": 1             }         }     }      graphworkertype[key] = new array();      $.each(value, function(key2, value2) {         graphworkertype[key].push(key2);     });      console.log(graphworkertype); {         {             object {                 full - time: array[7], part - time: array[5]             }             full - time: array[7]             0: "php"             1: "nosql"             2: "webex"             3: "facebook"             4: "wordpress"             5: "excel"             6: "access"             part - time: array[5]             0: "wordpress"             1: "xml"             2: ".net"             3: "adobe photoshop"             4: "visual basic"         }     } }); 

modify section

graphworkertype[key] = new array(); $.each(value, function(key2, value2 ) {         graphworkertype[key].push(key2); }); 

with

graphworkertype[key] = { labels: [], values: []}; $.each(value, function(key2, value2 ) {     graphworkertype[key]['labels'].push(key2);     graphworkertype[key]['values'].push(value2); }); 

then can pass graphworkertype object chart


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -