Disable Auto Chart Move on new data push

1 week ago 15
ARTICLE AD BOX

In AmCharts 5, when a new data is pushed into the series (Line Series or Candlestick Series whatever), the chart is moved a little bit to adjust the position for the new one. It is the default behavior. I need to disable this.

Why? Well, it is a good feature when viewing the latest data. But when it comes to viewing history, its pretty annoying. You can see in the video how the chart moved while viewing it.

What I have tried? I tried searching up the docs, but I didn't found anything about it. So I started adding my own mod. What I did is: when a new data is pushed i.e new candle is created, I just scroll back to the previous position. Example:

let prevDL = 0; let prevPos = [0, 0]; this.root.events.on('frameended', ()=>{ let start = this.dateAxis.getPrivate('selectionMin'); let end = this.dateAxis.getPrivate('selectionMax'); let dl = this.valueSeries?.data.length; if (!(start && end && dl && this.valueSeries)) return; let pos = [start, end]; if (prevPos[0] && prevPos[1] && prevDL && prevDL < dl) { this.dateAxis.setAll({ start: this.dateAxis.valueToPosition(prevPos[0]), end: this.dateAxis.valueToPosition(prevPos[1]) }); pos = prevPos; } prevPos = pos; prevDL = dl; });

Well, the problem is that... it creates a glitchy effect. The chart moves to the new candle and again moves back to the previous position very fast!

Here is a demo jsFiddle and demo video.

Read Entire Article