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 8767239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:45:34+00:00 2026-06-13T16:45:34+00:00

I am making a plot with different circles on it. Each circle has a

  • 0

I am making a plot with different circles on it. Each circle has a fixed position, but the size of each circle can be changed seperately via an html input field.

The code is use for the input field is this:

<input type="text" id="size1" class="size" value="" style="width: 30px;">

I have saved the data in this dataset:

var dataset = [{name: "circle1", xpos: -413, ypos: 278, color: "black", radius: $('#size1').val(),},
            {name: "circle2", xpos: -161, ypos: 290, color: "black", radius: $('#size2').val(),}];

This is how I draw the circle:

function drawCircle () {
            svg.selectAll("circle").remove();
            svg.selectAll("circle")
               .data(dataset)
               .enter()
               .append("svg:circle")
               .attr("cx", function(d){
                        return xScale(d.xpos);})
               .attr("cy", function(d){
                        return yScale(d.ypos);})
               .attr("r", function (d){            
                        return rScale(d.radius);})                          
               .attr("fill", "rgb(100,0,0)")
               .attr("opacity", "0.7");
        }

Lastly I make a trigger that when something changes, the circle is drawn again:

$('.size').change(function(){
            radius = $(this).val(); 
            svg.selectAll("circle")
               .transition()
               .duration(750)
               .attr("r", function (d){            
                        return rScale(radius);})
        });

This way when I change a value in #size1 or #size2, both circles are redrawn with the value that is last inputted.

My question is: How can I update the dataset in a way that each circle will ‘listen’ to his own input field?

  • 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-13T16:45:35+00:00Added an answer on June 13, 2026 at 4:45 pm

    I assume that you have multiple input-fields.

    What you can do when you have a change on one of the fields, recreate the dataset and repaint the circles.

    The static data for your dataset can be stored in a data-attribute on the input.

    Like this:

    HTML

    <input type="text" id="circle1" class="size" value="" style="width: 30px;" data-circle='{"name": "circle1", "xpos": -161, "ypos": 290, "color": "black" }'>
    

    javascript

    function drawCircles (dataset) {
            svg.selectAll("circle").remove();
            svg.selectAll("circle")
               .data(dataset)
               .enter()
               .append("svg:circle")
               .attr("cx", function(d){
                        return xScale(d.xpos);})
               .attr("cy", function(d){
                        return yScale(d.ypos);})
               .attr("r", function (d){            
                        return rScale(d.radius);})                          
               .attr("fill", "rgb(100,0,0)")
               .attr("opacity", "0.7");
        }
    
    $('.size').change(function(){
            var dataset = [];
            $('.size').each(function(index,item) {
              var circleData = item.data('circle');
              var circleData['radius'] = $(item).val();
              dataset.push(circleData);
            });
            drawCircles(dataset);
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I calculate the maximum histogram value when making a plot? I want
How can I create a plot title in ggplot2? Am I making a silly
In Hadley Wickham's ggplot2 book in chapter 10.3, he alludes to making plot functions.
Making a new site but something is happening to it in IE8. The social
Making a new site but something is happening to it in IE. I've purchased
I'm trying to plot a bar chart in ggplot2 where each factor gets the
The question plot (a bit abstract, but answering this question will help me in
I'm making a plot in R I'd like to have a symbol appear at
I am making a very simple plot in R and would like the change
I want axis labels for a plot I'm making, and naturally the y-axis label

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.