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

  • Home
  • SEARCH
  • 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 8047807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:13:15+00:00 2026-06-05T06:13:15+00:00

I am having a hard time figuring out this piece of code marked in

  • 0

I am having a hard time figuring out this piece of code marked in bold. Can some explain me those lines please

function growBars() {
    var barStartX = 0;
    var barStartY = 0;
    var barHeight = 0;
    var barValue = 0;

    <!-- ********** Start Unable to understand -->
    barValue = parseInt(chartData.bars[i].value);
    barHeight = (barValue * chartHeight / maxValue) / numSteps * idxStep;
    barStartX = chartMargin + chartAxisSpace + (i * (barWidth + barMargin)) + barMargin;
    barStartY = chartMargin + (chartHeight - barHeight);
    drawBar(barStartX, barStartY, barWidth, barHeight);
}
if (idxStep < numSteps) {
    idxStep++;
    setTimeout('growBars()', growSpeed);
}
} < -- * * * * * * * * * * * * * End till here-- >

function drawBar(barX, barY, barW, barH) {
    context.fillStyle = '#00c';
    context.fillRect(barX, barY, barW, barH);
    context.shadowOffsetX = 3;
    context.shadowOffsetY = -3;
    context.shadowBlur = 3;
    context.shadowColor = 'rgba(200, 200, 200, .3)';
    context.strokeStyle = '#000';
    context.lineWidth = 1;
    context.strokeRect(barX, barY, barW, barH);
}

As you can see the above code draws bars on a graph. What I am unable to understand is the way this recursive function is used. What does that piece of code do?

  • 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-05T06:13:17+00:00Added an answer on June 5, 2026 at 6:13 am
    1. barValue = parseInt(chartData.bars[i].value);
    2. barHeight = (barValue * chartHeight / maxValue) / numSteps * idxStep;
    3. barStartX = chartMargin + chartAxisSpace + (i * (barWidth + barMargin)) + barMargin;
    4. barStartY = chartMargin + (chartHeight-barHeight);
    5. drawBar(barStartX, barStartY, barWidth, barHeight);
    
    1. Converts chartData.bars[i].value to integer
    2. sets the bar height; Im not sure what numSteps or idxStep is
      3/4. sets bar x,y start coords
    3. calls the drawBar function with the values calculated above.

    Its not recursive although you don’t need the recall to the function unless you plan on your graph illustrating a growth in the data

    function growBars() { //START OF FUNCTION
        var barStartX = 0;
        var barStartY = 0;
        var barHeight = 0;
        var barValue = 0;
    
        <!-- ********** Start Unable to understand -->
        barValue = parseInt(chartData.bars[i].value);
        barHeight = (barValue * chartHeight / maxValue) / numSteps * idxStep;
        barStartX = chartMargin + chartAxisSpace + (i * (barWidth + barMargin)) + barMargin;
        barStartY = chartMargin + (chartHeight - barHeight);
        drawBar(barStartX, barStartY, barWidth, barHeight);
    } //END OF FUNCTION
    if (idxStep < numSteps) { //START OF IF STATEMENT
        idxStep++;
        setTimeout('growBars()', growSpeed);
    } //END OF IF STATEMENT
    } < -- * * * * * * * * * * * * * End till here-- > // UNPAIRED CLOSE BRACKET
    
    function drawBar(barX, barY, barW, barH) {
        context.fillStyle = '#00c';
        context.fillRect(barX, barY, barW, barH);
        context.shadowOffsetX = 3;
        context.shadowOffsetY = -3;
        context.shadowBlur = 3;
        context.shadowColor = 'rgba(200, 200, 200, .3)';
        context.strokeStyle = '#000';
        context.lineWidth = 1;
        context.strokeRect(barX, barY, barW, barH);
    }
    

    as you can see from my comments, the growbars is not called from within itself thus it is not recursive

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

Sidebar

Related Questions

I'm having some hard time figuring out what's wrong in this simple code: This
I'm having a hard time figuring out why this is not working. I have
Having a hard time figuring out the best way to do this... I have
I'm having a hard time figuring out how best to do this. I have
I'm having a hard time figuring this one out. Seems like no matter what
I'm having a hard time figuring this out but how do I tell my
Having a hard time figuring out the best way to go about this. What
Apologies if this is a repeat; I'm having a hard time figuring out what
I'm having a hard time figuring out how to architect the final piece of
I'm having a hard time figuring out how to do this if statement. I

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.