Hi,
I need to build an interactive pie chart in GUI. I need to be able to manipulate the areas in the graph by dragging the boundaries between 2 areas. I don’t know how to approach this problem.
Any idea? Thank you!
Hi,
I need to build an interactive pie chart in GUI. I need to be able to manipulate the areas in the graph by dragging the boundaries between 2 areas. I don’t know how to approach this problem.
Any idea? Thank you!
Attatch this code to your camera and create a plane with the picture at the bottom. Make sure when you upload the pic it is uploaded as GUI. In the inspector of the camera, set the fraction, size, and position you initially want your pie chart to have and select your plane for the “Slice”. Finally, create a tag named “Slice” and your done!
var slice : Transform;
var fraction : float;
var piePosition : Vector3;
var pieDiameter : float;
function Update(){
Pie();
}
//now the slider that will determine the number of times it needs to instantiate
function OnGUI () {
fraction = LabelSlider (Rect (20, 100, 50, 20), fraction, 360.0, Mathf.RoundToInt(fraction)+"/360");
if (GUI.Button(Rect(10,70,50,30),"Chart"))
Pie();
}
function LabelSlider (labelRect : Rect, sliderValue : float, sliderMaxValue : float, labelText : String) : float {
GUI.Label (labelRect, labelText);
sliderValue = GUI.HorizontalSlider (Rect (70, 100, 360, 20),sliderValue, 0.0, sliderMaxValue);
return sliderValue;
}
function Pie(){
var slices : GameObject[];
slices = GameObject.FindGameObjectsWithTag("Slice");
for(var slice : GameObject in slices){
Destroy(slice);}
for (var i : int = 0;i < Mathf.RoundToInt(fraction); i++) {
var clone : Transform;
clone = Instantiate (slice, Vector3(0,0,0), Quaternion.Euler(i*1,90,270));
clone.parent = this.transform;
clone.localPosition = piePosition;
clone.localScale = Vector3(pieDiameter, 1, pieDiameter);
clone.gameObject.tag = "Slice";
}
}
Good luck on the project!
I happen to know there are something like chart controls being able to create the thing you described. Unfortunately, the one doesn’t seems to solve the problem in flash. However, some chart types are offered. You can take a look, if smooth, get some insights.