D3.JS time-series line chart with real-time data, panning and zooming

后端 未结 1 2030
被撕碎了的回忆
被撕碎了的回忆 2021-02-13 18:52

FIDDLE <<<< this has more up to date code than in the question.

I am trying to create a real-time (live-updating) time-series chart in d3, t

相关标签:
1条回答
  • 2021-02-13 19:06

    Instead of plotting the whole data and clipping the unnecessary parts, you could keep a global array of all values that you just slice each time you need to update the graph. Then you can more easily recompute your x axis & values. Downside is you cannot easily have a transition.

    So, you would have two variables:

    var globalOffset = 0;
    var panOffset = 0;
    

    globalOffset would be updated each time you populate new values and panOffset each time you pan. Then you just slice your data before plotting:

    var offset = Math.max(0, globalOffset + panOffset);
    var graphData = globalData.slice(offset, offset + 100);
    

    See fiddle for complete solution.

    0 讨论(0)
提交回复
热议问题