Skip to main content

Posts

Showing posts from December, 2014

Showing Bar Graph in unity

Hi, today i will be showing how to make a bar graph in unity3d. Take a look at this screen shots.



I used line renderers for lines. My origin start from (0,0) and  X axis goes to 4 and Y axis goes to 3.
I took X axis to represent number of data and Y axis to show the value of that data.

I even implemented simple animation to the line renderers. which you can check in the video.




So here is the script.

usingUnityEngine;
usingUnityEngine.UI;
usingSystem.Collections;
usingSystem.Collections.Generic;

publicclassBarGraphManager : MonoBehaviour {

publicGameObjectlinerenderer;
publicGameObjectpointer;

publicGameObjectHolderPrefb;

publicGameObjectholder;

publicMaterialmat;

publicTexttopValue;

publicList<GraphData> graphData = newList<GraphData>();

privateGraphDatagd;
privatefloathighestValue;

voidStart(){
UpdateData();
    }

publicvoidUpdateData() {

//InstantiateanemptygameObjecttoholdalllinerenderers
holder = Instantiate(HolderPrefb,Vector3.zero,Quaternion.identity) asGameObject;
holder.name