0

I have array items as my code below, I want to push these Array items "keywords_name" or "keywords_name" into Chart.js library that i used. I can use as what i did below by calling each array item in "labels" or "dataset" but i guess thats should not be the way.

// Top keywords.
            var keywords_name = [];
            var keywords_num = [];

            for(i = 1; i<=10; i++){
                keywords_name.push($("#content .box_segment:eq(1) table tbody tr:nth-child("+i+") td:first").text());
                keywords_num.push(parseInt($("#content .box_segment:eq(1) table tbody tr:nth-child("+i+") td:last").text()))
            }

            var bardata = {
                labels : [keywords_name[1], keywords_name[2], keywords_name[3], keywords_name[4]],
                datasets : [
                    {
                        fillColor : "rgba(220,220,220,0.5)",
                        strokeColor : "rgba(220,220,220,1)",
                        data : [1,2,3,4]
                    }
                ]
            }
2
  • 2
    why dont you send your array directly ? { labels : keywords_name } Commented Apr 16, 2013 at 7:51
  • you are right, my mistake! Commented Apr 16, 2013 at 7:54

1 Answer 1

1

Why don't you just assign the obtained arrays to the new bardata object like this?:

var bardata = {
               labels : keywords_name,
               datasets : {
                           fillColor : "rgba(220,220,220,0.5)",
                           strokeColor : "rgba(220,220,220,1)",
                           data : keywords_num
                          }
              }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.