Draw XXL documentation


public void AddValue(...)

There are several ways to add datapoint values to chart lines. Let's start with the most easy one:

Draw XXL charts have by default premade lines for several data types build in. So for example if you want to draw a graph line from one of your float members you can supply your values to the chart with nothing more than:
		
    void Update()
    {
        aChart.AddValue(myFloatDataPoint);
    }
		
The "myFloatDataPoint" from the code example defines a y-value in the chart. The x-value is defined by aChart.xAxis.sourceOfAutomaticValues (todo link), whose default setting is "fixedStepForEachValueAdding". In the code example this means that each Update() cycle increments the x-position by 1. So it resembles a classical chart where the values go from left to right.

The same approach works if you don't supply float values, but integer or bool values, because the AddValue() function has overloads for multiple different data types:

public void AddValue(float yValueOfNewDataPoint);
public void AddValue(int yValueOfNewDataPoint);
public void AddValue(Vector2 yValueOfNewDataPoint);
public void AddValue(Vector3 yValueOfNewDataPoint);
public void AddValue(Vector4 yValueOfNewDataPoint);
public void AddValue(Color yValueOfNewDataPoint);
public void AddValue(Quaternion yValueOfNewDataPoint); //displays euler angles
public void AddValue(bool yValueOfNewDataPoint); //"false" becomes "0", "true" becomes "1"
public void AddValue(GameObject yValueOfNewDataPoint); //uses the "Transform" data values
public void AddValue(Transform yValueOfNewDataPoint);

Some data types from the overloads are made up of more than one component. For example "Vector3" consists of x, y and z. This will draw 3 lines to the chart instead of one: One for each component. Transform consists of even 9 components, resulting in 9 lines. You can disable components where you are not interessted in via dataComponentsThatAreDrawn(todo link).

Now what about cases where you want to draw multiple float values as multiple separate lines? The above described approach with premade lines reaches its limits for that requirement, because it offers only one line for floats. For such cases there is the option to create own lines. Again there are different ways to achieve that. Let's start with a simple one::

You can extend the already known "AddValue()" function with a string parameter like so:

public void AddValue(float yValueOfNewDataPoint, string nameOfReceivingLine);

The code then becomes this:
		
    void Update()
    {
        aChart.AddValue(myFloatDataPoint, "my line name");
    }
		
When this "lineName" string parameter is used then a new line with that name is created behind the scenes. This way you can have as many custom lines in your chart as you want. For example:
		
    void Update()
    {
        aChart.AddValue(myDatapointForLine1, "Name of Line 1");
        aChart.AddValue(myDatapointForLine2, "Name of Line 2");
        aChart.AddValue(myDatapointForLine3, "Name of Line 3");
        aChart.AddValue(myDatapointForLine4, "Name of Line 4");
        aChart.AddValue(myDatapointForLine5, "Name of Line 5");
    }
		
Another way of adding lines is using the explicit "AddLine"() function (todo link) of the chart. This returns a line object reference that also has an "AddValue()" function. Moreover you can then change other properties of the line (like color, name, thickness, ...), since you have a reference to it. See the usage example:
		
    ChartDrawing myChart;
    ChartLine myLine1;

    void Start()
    {
        myChart = new ChartDrawing();
        myLine1 = myChart.AddLine("My Line");
    }

    void Update()
    {
        myLine1.Color = Color.red;
        myLine1.AddValue(myFloatDataPoint);
    }		

Other ways of adding data point values are supplied by the "AddXYValue" (todo link) and "AddValues_eachIndexIsALine"(todo link) functions.