Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:14:19+00:00 2026-06-04T06:14:19+00:00

I am modifying this code: https://github.com/jasondavies/d3-cloud <script> d3.layout.cloud().size([300, 300]) .words([ Hello, world, normally, you,

  • 0

I am modifying this code: https://github.com/jasondavies/d3-cloud

<script>
  d3.layout.cloud().size([300, 300])
      .words([
        "Hello", "world", "normally", "you", "want", "more", "words",
        "than", "this"].map(function(d) {
        return {text: d, size: 10 + Math.random() * 90};
      }))
      .rotate(function() { return ~~(Math.random() * 2) * 90; })
      .fontSize(function(d) { return d.size; })
      .on("end", draw)
      .start();

  function draw(words) {
    d3.select("body").append("svg")
        .attr("width", 300)
        .attr("height", 300)
      .append("g")
        .attr("transform", "translate(150,150)")
      .selectAll("text")
        .data(words)
      .enter().append("text")
        .style("font-size", function(d) { return d.size + "px"; })
        .attr("text-anchor", "middle")
        .attr("transform", function(d) {
          return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
        })
        .text(function(d) { return d.text; });
  }
</script>

I’d like to get the word and size data from separate JSON data.
I have two variables

jWord = ["abc","def","ghi,"jkl"];
jCount = ["2", "5", "3", "8"];

jWord has the words that I want to display in the tag clouds.
jCount is the size of the corresponding word (same order).

I switched to the word to jWord, but not sure how to switch the size part in

      .words(jWord.map(function(d) {
        return {text: d, size: 10 + Math.random() * 90};
      }))

I also have another Json format variable.

jWord_Count = ["abc":2, "def":5, "ghi":3, "jkl":8 ];

If this format helps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:14:20+00:00Added an answer on June 4, 2026 at 6:14 am

    Try d3.zip: d3.zip(jWord, jCount) returns a merged array where the first element is the text and size of the first word [jWord[0], jCount[0]], the second element is the second word, and so on. For example:

    .words(d3.zip(jWord, jCount).map(function(d) {
      return {text: d[0], size: d[1]};
    }))
    

    In effect, d3.zip turns column-oriented data into row-oriented data. You could also just represent your data in row-oriented form to begin with:

    var words = [
      {text: "abc", size: 2},
      {text: "def", size: 5},
      {text: "ghi", size: 3},
      {text: "jkl", size: 8}
    ];
    

    Lastly, watch out with types. Your counts are represented as strings ("2") rather than numbers (2). So you might want to use + to coerce them to numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am modifying the TouchImageView ( https://github.com/MikeOrtiz/TouchImageView/issues ) to have zoom in and out
I'm trying to import the ZXing project in Eclipse, http://code.google.com/p/zxing/ following this guide http://knol.google.com/k/alec-go/modifying-the-android-barcode-scanner/2vd5zn6va2fqd/2#
I am talking about this line of code <link rel=alternate type=application/rss+xml title=example.com &raquo; Comments
I'm using this library: PB for ObjC http://code.google.com/p/metasyntactic/wiki/ProtocolBuffers . The problem is I can't
EDIT: This question is about finding definitive reference to MySQL syntax on SELECT modifying
I'm working on modifying some existing code for a payment gateway and I'm not
I am modifying my PHP network's code to have user roles like wordpress here
I'm modifying some code that calls enumerate on a list declared via a list
I'm trying to get a node.js server to send css files. I'm modifying this
I found this example PHP source code at HTTP POST from PHP, without cURL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.