Skip to main content

Real-time data

Adding data in real-time is mostly handled similarly to adding static data, although it must always be done in code. Here are some general guidelines to follow:

  • Use addDataPoint() method when adding one data point at a time.

  • Use addDataArray() method when adding multiple data points at the same time.

  • If the dataset needs to be scrolled after new points have been added, set the scroll parameter true when using the above methods. The data is then moved left based on the number of added data points. Unless data limit settings (see the next chapter) state otherwise, the out-scrolled data points are not removed from the chart, and can still be seen by panning the chart or zooming out.

  • Data points can only be added to the end of the existing data. Therefore, make sure the datetime values of the added data points are newer than the current newest data point on the chart. If this condition is not fulfilled, the points won't be added to the chart. If you need to add data points at the beginning or somewhere in the middle of the dataset, setData() method has to be used to re-add the whole dataset.

  • Use updateLastDataPoint() when you need to update the latest data point, and the total data point count doesn't change. If you need to update more that just the latest point, the whole dataset needs to be re-added with setData() method.

  • In real-time applications, use setData() only when the whole dataset needs to be replaced. Otherwise use the add methods.

Check Adding data in code to see code examples about the above methods.


Dropping old data

Memory consumption can become a problem in real-time applications, if new data points are constantly being added and old ones never removed. For this, Technical Analysis Chart has a built-in feature to drop old data points, when the total number of points exceeds certain limit. As this feature is disabled by default, enableDataPointLimit() method has to be called to activate the limit. Afterwards, setDataPointLimit() can be used to set the maximum number of points allowed on the chart before old points are dropped out. Note that the dropped points are permanently removed from the chart and, unless re-added, cannot be viewed again.

// Enabling data point limit of one thousand points. 
tradingChart.enableDataPointLimit(true)
tradingChart.setDataPointLimit(1000)

Both of the above settings can also be found under the chart settings menu in the toolbar.