This articles describes the methods that manipulate the data on the candle chart. You can also view the tutorial in the folder In Beta/Tutorials/Candle
CLEARING A CATEGORY BEFORE APPENDING DATA
In many cases you would like to clear a category from all it’s previous data before appending new data. You can do that in the following way:
candle.DataSource.ClearCategory("Category");
HOW TO ADD DATA TO THE Candle CHART
You can both streaming and non streaming data using the method AddCandleToCategory :
double open,high,low,close,start,duration;
candle.DataSource.AddCandleToCategory("Candle 1", new CandleChartData.CandleValue(open,high,low,close,start,duration));
When adding streaming data , you can specify the animation time as well:
float animationTime = 1.0f; // one second
double open,high,low,close,start,duration;
candle.DataSource.AddCandleToCategory("Candle 1", new CandleChartData.CandleValue(open,high,low,close,start,duration),animationTime);
Use case example
Let’s say we would like to stream stock data from a remote network interface. Here is an example of how something like this can be done. In the following example we a NetworkStream the has been created and is connected to a remote source. It is assumed in this case that the remote application fills the buffer with candle defined using six doubles (open,high,low,close,start,duration).
int bufferOffset = 0;
// create a buffer that can hold one candle(six doubles)
byte[] buffer = new byte[sizeof(double) * 6];
private void Update()
{
// we read from the stream until the buffer fills.
// notice that we never read past the length of the buffer
bufferOffset += netwrokStream.Read(buffer, bufferOffset, buffer.Length - bufferOffset);
if(bufferOffset == buffer.Length) // if we have enough data in the buffer
{
double open,high,low,close,start,duration;
// we can extract the candle values from the buffer
open = BitConverter.ToDouble(buffer, 0);
high = BitConverter.ToDouble(buffer, sizeof(double);
low = BitConverter.ToDouble(buffer, 2* sizeof(double);
close = BitConverter.ToDouble(buffer,3* sizeof(double);
start= BitConverter.ToDouble(buffer,4* sizeof(double);
duration= BitConverter.ToDouble(buffer,5* sizeof(double);
CandleChart candle = GetComponent<CandleChart>();
// apply the point to the candle chart
candle.DataSource.AddCandleToCategory("Stock Data",new CandleChartData.CandleValue(open,high,low,close,start,duration), 1f);
bufferOffset = 0;
}
}