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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:38:40+00:00 2026-06-15T17:38:40+00:00

Basically, I want my graph to start at the x-axis and grow over two

  • 0

Basically, I want my graph to start at the x-axis and grow over two seconds to the actual data values. This is probably a simple thing, but I can’t seem to get it to work.

I’m appending an area element, in which the d=”” attribute is built by a function (area) and I’m not sure where to add a transition.

First I thought to do this in the area function, but this fails. I’ve also tried to do this when the area element is added without success.

Here is my code:

// Create the area element for each object - a function that will be passed to "path"
var area = d3.svg.area()
    .x(function(d) { return x(d.year); })
    .y0(height)
    //.y1(height)
    //.transition()
    //.duration(2000)
    .y1(function(d) { return y(d.average); });

// build the container SVG element
var svg = d3.select("#co2").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
    .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")")

svg.append("path") 
    // pull in data to the path 
    .datum(data)
    .attr("class", "area")
    // passing in the area function, for each object
    .attr("d", area)
    // starts the graph opacity at 0 and fades to 1 over 2.5 seconds
    .style("fill-opacity", "0")
    .transition()
    .duration(2500)
    .style("fill-opacity", "1");
  • 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-15T17:38:40+00:00Added an answer on June 15, 2026 at 5:38 pm

    Rather than try to use transition on the shape of the area graph, you could apply a scale(x,y) transform against the whole svg element that you want to animate. The advantage of this approach is that it is not limited to a particular rendering implementation (eg: not path/d3.area specific).

    There are a couple of gotchas to note though:

    • To avoid the transition() behaviour, working on the margin adjustments, make sure you have a separate ‘g’ element for the transition() transforms to act on

    • SVG has its origin (0,0) in the top-left, so in addition to scaling the SVG area, you need to set the base of the graph

    This is put together below:

    ‘g’ element:

    var svg = d3.select("#co2").append("svg")
        .attr("width", width + margin.left + margin.right)
        .attr("height", height + margin.top + margin.bottom)
      .append("g")
          .attr("transform", "translate(" + margin.left, "," + margin.top + ")")
        // define a new 'g' to scope the transition, and keep separate from the margin adjusting transform above
        .append("g"); 
    

    transition() including base adjustment:

    svg
      .attr("transform", "translate(0," + height + ") scale(1, 0)")
    .transition().duration(2000)
      .attr("transform", "translate(0,0) scale(1, 1)");
    

    As ever, this is best illustrated with the complete example: http://bl.ocks.org/4239516

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

Sidebar

Related Questions

I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
Basically I want to find a path between two NP tokens in the dependencies
Basically I want is to aggregate some values in a table according to a
I want to have a table with columns: id, user_id1, and user_id2. basically this
Possible Duplicate: Set Additional Data to highcharts series So I have this graph: http://jsfiddle.net/Gg3ZL/
In my program I want to draw a simple score line graph. I have
I want to graph the number of tweets and the number of followers over
I basically want something like: TextView Button Button . . . TextView TextView SeekBar
I basically want to setup a relationship similar to Netflix's DVD rental model. There
I basically want to do: git checkout branchA git checkout -b branchB <commit_id> which

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.