1. Home
  2. Docs
  3. Advanced Concepts
  4. Updating all points each frame

Updating all points each frame

Some use cases require that you change all points each frame. This is mostly required when displaying wave forms. In this article you will learn how to change all the points in the chart each frame. When using this feature , take into consideration that it is relatively performance intensive , so try to find the required minimum amount of points. You can see an example of this method in the asset folder in “Extras/ExampleScenes/Realtime”. Also consider optimizing for performance

Create an array to hold the data

DoubleVector3[] dataArr = new DoubleVector3[2000];

Modify the array from the update method of a monobehaviour

//repopulate the data array with random data
for (int i = 0; i < 2000; i++)
      dataArray[i] = new DoubleVector3(i, Random.value);

set the position array From the update method

var data = chart.DataSource.GetCategory("dataseries-1").Data;
// call one of the two
data.SetPositionArray(dataArray);

Example code

DoubleVector3[] dataArr = new DoubleVector3[2000];
    
void Update()
    {
        //obtain the category object from the chart
        var data = chart.DataSource.GetCategory("cat12").Data;
        //repopulate the data array with random data
        for (int i = 0; i < 2000; i++)
            dataArray[i] = new DoubleVector3(i, Random.value);
        //apply the data to the chart each frame
        data.SetPositionArray(dataArray, 0, dataArray.Length);
    }