1. Home
  2. Docs
  3. Basic Concepts
  4. Loading data into a category

Loading data into a category

The graph chart is made of categories. Each category holds a data object that can be use in order to load data. you can learn how to set up a chart’s categories right here

Obtaining a data object

You can obtain the data object for a category in the following way

public CanvasDataSeriesChart chart; // set from the unity inspector

var cat = chart.DataSource.GetCategory("dataseries-1"); // make sure the category name matches the name in the inspector
if(cat == null)
{
   // the category does not exist in the chart
   return;
}

var data = cat.Data; // data object is ready to be used

Filling the Data object with data

// There are 3 methods in the data object
data.Clear(); //clears all the previous data

data.Append(x,y); // appends a new point to the data

DoubleVector3[] arr = new arr[100];
data.SetPositionArray(arr); // clears the data and copies the content of the array into the category

Use case example : Numbers

public CanvasDataSeriesChart chart; // set from the unity inspector
var data = chart.DataSource.GetCategory("dataseries-1").Data;

for(int i=0; i<100; i++) // appends 100 points with random y values
   data.Append(i,Random.Range(-5f,5f));

Use case Example : Dates

public CanvasDataSeriesChart chart; // set from the unity inspector
var data = chart.DataSource.GetCategory("dataseries-1").Data;

var now = DateTime.Now;
for(int i=0; i<100; i++) // appends 100 points with random y values
   data.Append(now + TimeSpan.FromDays(i),Random.Range(-5f,5f));