1. Home
  2. Docs
  3. Radar Chart
  4. Radar Categories and Groups
  5. Configuring groups and categories from script

Configuring groups and categories from script

This article is about adding , removing and changing the visual features of categories and groups from script. If you want to lean how to fill the radar chart with data , see the Radar Chart Tutorial and Filling the radar chart with data

Like any feature of graph and chart, The radar categories and groups are completely configurable from script. You may want to take a look at Obtaining a chart object for scripting before proceeding with this article. For an alternative way of configuring categories with Graph and Chart , check out Storing and restoring category prefabs

Also , you may want to look at Category Settings for a quick overview of the visual properties of radar categories .

How to load material and Prefabs into your script

In order to configure a category you may need to pass materials and prefabs as parameters in your script. You can obtain these parameters in the very same way you would with any unity resources. Check out these two links for more information :

ADDING AND REMOVING CATEGORIES AND GROUPS

You can add a 2D category to the radar chart in the following way :

// these can be assigned from a monobehviour inspector
public Material lineMaterial,pointMaterial,fillMaterial;
float pointSize = 3f, lineThickness = 1f;

//on newer versions of graph and chart
radar.DataSource.AddCategory("newCategory",lineMaterial,lineThickness,pointMaterial,pointSize,fillMaterial)

//on older versions of graph and chart
radar.DataSource.AddCategory("newCategory",null,lineMaterial,lineThickness,null,pointMaterial,pointSize,fillMaterial)

You can add a 3D category to the radar chart in the following way:

// these can be assigned from a monobehviour inspector
public Material lineMaterial,pointMaterial,fillMaterial; 
float pointSize = 3f, lineThickness = 1f;
float curve = 0f , separation = 0f;
// these can be assigned from a monobehviour inspector
public PathGeneration linePrefab; 
public GameObject pointPrefab;

radar.DataSource.Add3DCategory("newCategory", linePrefab, lineMaterial, lineThickness, pointPrefab, pointMaterial, pointSize, fillMaterial, fillSmoothing, curve, seperation);

You can remove a category in the following way :

radar.DataSource.RemoveCategory("oldCategory");

You can add and remove groups in the following way:

 radar.DataSource.AddGroup("newGroup");
 radar.DataSource.RemoveGroup("oldGroup");

SETTING CATEGORY STYLES FROM SCRIPT

All visual features of categories can be controlled from script. This can be done with separate methods for 2d and 3d styles. Let’s have a look:

You can set the hover prefabs of a 2D radar category in the following way:

// these can be set from a monobehviour inspector
public ChartItemEffect lineHover, pointHover;

radar.DataSource.SetCategoryHover("category", lineHover, pointHover);

You can set the orientation of a 3D radar category with the following code:

float curve = 0f , separation = 0f; 
radar.DataSource.Set3DCategoryOrientation("category", separation, curve);

You can set the fill style of a 2D or 3D category like this:

public Materail fillMaterial;

// for a 2D category
radar.DataSource.SetCategoryFill("category",fillMaterial);

float smoothing;
// for a 3D category
radar.DataSource.Set3DCategoryFill("category",fillMaterial,smoothing);

You can set the line style of a 2D or 3D category with the following methods :

public Materail lineMaterial;
public float lineThickness = 1f;

// for a 2D category
radar.DataSource.SetCategoryLine("category",lineMaterial,lineThickness);

public PathGeneration linePrefab; 

// for a 3D category
radar.DataSource.Set3DCategoryLine("category",linePrefab,lineMaterial,lineThickness)

You can set the points style of a 2D or 3D radar category with the following code :

public Material pointMaterial;
float pointSize = 3f;

//for a 2D category
radar.DataSource.SetCategoryPoint("category", pointMaterial, pointSize);

public GameObject pointPrefab;

//for a 3D category
radar.DataSource.Set3DCategoryPoint("category", pointPrefab, pointMaterial, pointSize);

RENAMING A CATEGORY or a group

you can rename a category or a group in the following way , make sure the new name does not exist in the chart

radar.DataSource.RenameCategory("oldName","newName") 
radar.DataSource.RenameGroup("oldName","newName") 

removing all categories and groups

You can remove all categories or groups at once . It can be done in the following way:

radar.DataSource.ClearCategories();
radar.DataSource.ClearGroups();

Checking if a category or a group exists in the radar chart

if(radar.DataSource.HasCategory("categoryName"))
{
}
if(radar.DataSource.HasGroup("groupName"))
{
}