Accepted answer

The problem is with your use of .concat(). It merges the arrays without taking any points out. What you should do instead depends on what you're trying to do with the data. If you want to get rid of all of your old points, you can just overwrite data with data2add.

If you want to add your new data and then keep a certain range of your old data, you can use .filter() on your old array before .concat(). Just create a filtering function that checks to see if the element is both within your range and not equal to anything in the other array. This would look something like the following:

function filterFunction(value, i, thisArray){
    //Check to see if point is in range
    if(value < maxRange && value > minRange){

        //Note that you might have to change this depending on how 'equal' 
        //your elements are. You could also iterate through and check the dates, for

        return (newDataArray.indexOf(value) > -1 ? 0 : 1)

    return 0;


for zoom and update line chart with include zoom data exemple here:

  1. filter old data for not include duplicate area
  2. concat filtered data with zoom data
  3. Sort New array of data dy date
  4. rebuild serie of dot
  5. redraw curve dot and axis, but curve need draw like"path.line").attr("d", line(data)); instead of"path.line").attr("d", line);

for draw and redraw Attribute of line and Dots

 g.updateCurve = function(_){
    // Update the line path."path.line")
    .attr("d", line(_));

    // add each point
    .attr("cx", function(d) {return xScale (; })
    .attr("cy", function(d) {return yScale (d.ySpeed); })
    .attr("r", function(d) {return rScale (d.xSpeed)*2; });

    return this;

for draw and redraw axxis

g.drawAxis = function(){
    // Update the x-axis.".x.axis")
        .attr("transform", "translate(0," + xPos + ")")
        .attr("transform", "translate(0,0)")
    return this;

for zoom and replace part of data

function zoom(g) {
   var data2add=[

  data2add =, i) {
                  return {
            , d, i),
            , d, i),
            , d, i),
            , d, i),
            , d, i)

  mergedata = data.filter(function(element, index, array){
      return (<data2add[0].date ||>data2add[data2add.length-1].date);
  .sort(function (a, b) {
  // .sortBy( function(){ return } ); //

  var newDots = g.selectAll('circle')
                 // define new [data]
                 .data(mergedata, function(d) { return; });
  newDots.exit().remove(); // exit() content the deprecated points, remove it
  newDots.enter().append("circle")// enter() content the new points, draw it
   .attr("class", "dot");

     .drawAxis ();

Related Query

More Query from same tag