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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:05:13+00:00 2026-06-08T13:05:13+00:00

I have a simple line chart being fed from a web socket connection and

  • 0

I have a simple line chart being fed from a web socket connection and i’m applying a “monotone” filter to smooth out the lines, so to avoid seeing the lines adjust as new data comes in I am clipping the chart to hide the most recent data points as advised in this article…

http://bost.ocks.org/mike/path/

but this makes my axis look incorrect, the right edge has a gap showing the difference between the clip rect and the real output domain as you can see…

enter image description here

I have been able to fix this by adding a different x scale that reduces the size of the domain to the clip rect but that seems hacky to me, and not a particularly clean solution.

Is there a correct way to fix this?

Here is an abbreviated code listing showing the relevant portions…

// Create an x-scale
var x = d3.scale.linear()
    .domain([0, saved_points])
    .range([0, width - margin]);

// Create the axis
var xAxis = d3.svg.axis()
            .scale(x)
            .tickSize(-height)
            .tickValues([10,20,30,40,50,60,70,80,90]);

// Clip path truncates the last two points from the line, because adding new
// control points alters the shape of the line, and it "wiggles"
chart.append("defs")
    .append("clipPath")
    .attr("id", "clip")
    .append("rect")
    .attr("width", width - margin - x(2))
    .attr("height", height);

// Create the stack of lines
y_bands = d3.scale.ordinal().rangeBands([0,height]);
line = d3.svg.line()
    .x(function(d,i){ return x(i); })
    .y(function(d,i){
        var a = -1.0 * (y(d.value) / y_bands.domain().length);
        var b = y_bands(d.name);
        var result = a + height - b;
        return result;
    })
    .interpolate("monotone");

// Put the Axis at the bottom of the graph
d3.select("svg")
    .append("svg:g")
    .attr("class", "xaxis")
    .attr("transform", "translate(0," + (height) + ")")
    .call(xAxis);

// Finally create all the paths
chart.selectAll("path")
    .data(my_line_chart.values)
    .enter()
    .append("g")
    .attr("clip-path", "url(#clip)")
    .append("svg:path")
    .attr("class", "line_chart")
    .attr("stroke", function(d, i) { return color(i); })
    .attr('d', function(d,i){ return line(my_line_chart.values[i]);} );
  • 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-08T13:05:14+00:00Added an answer on June 8, 2026 at 1:05 pm

    I haven’t found an ideal solution for this but the technique I mentioned in my question does work.

    By creating a second scale that matches the clip path size instead of the actual data range I can draw the axis with that and have them match up.

            // define actual scales
            var x = d3.scale.linear()
                .domain([0, saved_points])
                .range([0, width - margin]);
    
            // Define a scale that's reduced in size of the output range by the
            //  length of two points of the actual scale.
            var fake_x = d3.scale.linear()
                .domain([0, saved_points - 2])
                .range([0, width - margin - x(2)]);
    
            // Use this fake scale for the axis instead of the real scale.
            var xAxis = d3.svg.axis()
                        .scale(fake_x)
                        .tickSize(-height)
                        .tickValues(ticks);
    
            // The clip path uses the same width reduced by two points
            chart.append("defs")
                .append("clipPath")
                .attr("id", "clip")
                .append("rect")
                .attr("width", width - margin - x(2))
                .attr("height", height);
    

    The only disadvantage i’ve seen to this method is that animating the width has issues because that x(2) value in the fake_x scale doesn’t transition.

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

Sidebar

Related Questions

I have a simple JSF line chart that uses PrimeFaces (via jqPlot) library: <p:lineChart
I have made a simple Line Chart: Which is showing 4 grid-lines at points
I have implemented a simple D3.js line chart that can be zoomed and panned.
Let's say I have a simple line chart with 5 values (a = 155,
I have a C# windows form with a simple 2D line chart that I
I have create simple line chart using Android Plot library. what i want to
I have a simple non scrollable xy line chart. I am showing a timer
I have a very simple line graph I'm trying to create in gRaphael. My
I have a simple in-line edit in my grid, and I want to commit
Say you have a simple loop while read line do printf ${line#*//}\n done <

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.