简体   繁体   English

初始化时删除d3轴过渡

[英]Remove d3 axis transition on initialization

I am using this example to create my own real-time graph using d3. 我正在使用此示例使用d3创建自己的实时图形。 In my version the graph is initialized with existing data. 在我的版本中,该图使用现有数据进行了初始化。 Problem is, the x-axis initialization causes a very small portion of the graph to show while it is transitioning or collapsing on the right before finally showing the normal scale and resultantly the normal graph. 问题是,x轴初始化会导致图形的一小部分显示出来,而该图形正在向右平移或塌陷,然后才最终显示正常比例尺,进而显示正常图形。 I am pretty sure the axis is causing it because the moment the axis returns to normal so does the graph. 我很确定是轴引起了它,因为当轴恢复正常时,图形也是如此。 Is there a way to remove this transition at the begging or otherwise have it not skew the graph or not show until it is ready? 有没有一种方法可以在开始时消除此过渡,否则它不会使图形倾斜或在准备好之前不显示? Here is the problem in action, better than me trying to explain it: http://codepen.io/Dordan/pen/NbBjPB/ 这是实际存在的问题,比我尝试解释的要好: http : //codepen.io/Dordan/pen/NbBjPB/

Here is the code snippet for creating the x-axis: 以下是用于创建x轴的代码段:

var limit = 60 * 1;
var duration = 750;
var now = new Date(Date.now() - duration);
var x = d3.time.scale().domain([now - (limit - 2), now - duration]).range([0, width]);

var axis = svg.append('g')
  .attr('class', 'x-axis')
  .attr('transform', 'translate(0,' + height + ')')
  .call(x.axis = d3.svg.axis().scale(x).orient('bottom'));

The instantiation of your x scale is missing the '* duration' when you're calculating the domain. 计算域时,x比例尺的实例缺少“ *持续时间”。 Use this instead and it works well: 改用它,效果很好:

var x = d3.time.scale().domain([now - (limit - 2) * duration, now - duration]).range([0, width]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM