1. Home
  2. Docs
  3. Pie/Torus Chart
  4. Pie Categories
  5. Configuring categories from script

Configuring categories from script

This article is about adding , removing and changing the visual features of categories from script.
If you want to lean how to fill categories with data , see Pie/Torus Chart and Filling the pie chart with data

Like any feature of graph and chart, The pie categories are completely configurable from script as well. 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 pie 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

You can add categories to the pie chart in the following way :

public Material pieMaterial;
public Color hover,selected;
double radiusScale = 1.0 ,depthScale = 1.0,depthOffset = 0.0;

var pie = GetComponent<PieChart>();
ChartDynamicMaterial dynamicMaterial = new ChartDynamicMaterial(Material,hover,selected);
pie.DataSource.AddCategory("newCategory",dynamicMaterial ,radiusScale,depthScale,depthOffset);

You can remove a category from the pie chart in the following way:

pie.DataSource.RemoveCategory("oldCategory");

Setting category styles from script

You can set the material of a pie category from script in the following way:

public Material pieMaterial;
public Color hover,selected;
ChartDynamicMaterial dynamicMaterial = new ChartDynamicMaterial(Material,hover,selected);        
pie.DataSource.SetMaterial("category",dynamicMaterial);

You can control the parameters of a pie category with the following call:

double radiusScale = 1.0 ,depthScale = 1.0,depthOffset = 0.0;
pie.DataSource.SetCateogryParams("category",radiusScale,depthScale,depthOffset);

Renaming a category

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

pie.DataSource.RenameCategory("prevName", "newName");

Removing all categories at once

pie.DataSource.Clear();

CHECKING IF A CATEGORY EXISTS IN A Pie CHART

if(pie.DataSource.HasCategory("category"))
{
}