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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:24:04+00:00 2026-06-18T04:24:04+00:00

I have been searching for quite a while but I haven’t been able to

  • 0

I have been searching for quite a while but I haven’t been able to figure it out.

I want to have a transition between two interpolations “basis” and “step-after” for a single line.

var time_scale, kpi_scale;
var line;

var data = [
{"kpi": 100, "time": 1317448800000},
{"kpi": 200, "time": 1320127200000},
{"kpi": 250, "time": 1322719200000},
{"kpi": 180, "time": 1325397600000},
{"kpi": 230, "time": 1328076000000},
{"kpi": 360, "time": 1330581600000},
{"kpi": 140, "time": 1333260000000},
{"kpi": 120, "time": 1335852000000},
{"kpi": 240, "time": 1338530400000},
{"kpi": 190, "time": 1341122400000},
{"kpi": 185, "time": 1343800800000},
{"kpi": 130, "time": 1346479200000},
{"kpi": 340, "time": 1349071200000},
{"kpi": 320, "time": 1351749600000},
{"kpi": 250, "time": 1354341600000}
];

// set up the viewport, the scales, and axis generators      
var container_dimensions = {width: 900, height: 400},
    margins = {top: 10, right: 20, bottom: 30, left: 60},
    chart_dimensions = {
        width: container_dimensions.width - margins.left - margins.right,
        height: container_dimensions.height - margins.top - margins.bottom
    };

var time_extent = d3.extent(
    data,
    function(d){return d.time;}
);

time_scale = d3.time.scale()
    .domain(time_extent)
    .range([0, chart_dimensions.width]);

var kpi_extent = d3.extent(
    data,
    function(d){return d.kpi;}
);

kpi_scale = d3.scale.linear()
    .domain(kpi_extent)
    .range([chart_dimensions.height, 0]);

var container = d3.select('body')
    .append('svg')
        .attr("width", container_dimensions.width)
        .attr("height", container_dimensions.height)
    .append("g")
        .attr("transform", "translate(" + margins.left + "," + margins.top + ")")
        .attr("id","chart");

draw_timeseries (data);
transitionToStepped (data);

function draw_timeseries (data) {
    line = d3.svg.line()
        .x(function(d){return time_scale(d.time);})
        .y(function(d){return kpi_scale(d.kpi);})
        .interpolate("basis");

    d3.select('#chart').append('path')
        .attr('d', line(data))
        .attr('id', 'line')
        .attr('class', 'line');               
}

function transitionToStepped (data) {

    line.interpolate("step-after");

    d3.select("#chart").selectAll(".line")
        .transition()
        .duration(2000)
        .attr("d", line(data))
        .delay(2000);           
}

I have saved a small jsfiddle containing my code.

jsFiddle Interpolation Transition

I wanted to “morph” between the basis line and the step-after line. But d3 is sliding in the step-after line from the left instead of “bending” the basis line into a step-after one.

Thanks for your help.
Christoph

  • 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-18T04:24:05+00:00Added an answer on June 18, 2026 at 4:24 am

    There has got to be a way to do this, and certainly one better than the offering below (I am looking forward to seeing other answers), but I have seen no answers here as of yet, and this will at least do a “morph” for you, although it also makes the line parallel to the x-axis during the transition. Not a terrible thing, but I believe not precisely what you are after.

    Here’s a fiddle for the full code and demo,
    modified from your original:
    http://jsfiddle.net/n5P6z/2/

    The meat of the approach is here:

    function xLineReduce() {
        line.x(function (d) {
            return time_scale(d.time);
        }).y(function (d) {
            return chart_dimensions.height;
        });
    }
    
    function resetInterpolator() {
        line.interpolate("cubic-in-out");
    }
    
    function stepItUp() {
        line.x(function (d, i) {
            return time_scale(d.time);
        })
            .y(function (d, i) {
            return kpi_scale(d.kpi);
        })
            .interpolate("step-after");
    }
    
    function transitionToStepped(myData) {
        path.data(myData)
            .call(xLineReduce)
            .transition()
            .delay(1000)
            .duration(500)
            .attr('d', line(myData));
    
        path.data(myData)
            .call(resetInterpolator)
            .transition()
            .delay(1500)
            .duration(0)
            .attr('d', line(myData));
    
        path.data(myData)
            .call(stepItUp)
            .transition()
            .delay(1500)
            .duration(500)
            .attr('d', line(myData));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching for quite a while now but i am unable to
I have been searching this for quite a while but couldn't find a solution
I have been searching for quite a bit now but I have never been
I have been searching quite a while now for how to read a nested
I've been searching and experimenting for a while with this, but I have had
I have been searching the web for an answer now for quite a while,
I've been searching for this for quite a while but can't seem to find
I have been searching for this for quite a while and couldn't find a
I have been searching for quite a while and cannot seem to find a
I have been searching for a solution for quite a while now and couldn't

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.