This is a migrated thread and some comments may be shown as answers.

Index error when setting OHLC Data Point

1 Answer 40 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shantimohan
Top achievements
Rank 1
Shantimohan asked on 29 Oct 2012, 03:55 PM

I want to display a single candlestick. My XAML & C# code are given below:

My XAML:

<telerikChart:RadCartesianChart x:Name="rccPerformanceOHLC"
                                Palette="Warm"
                                Margin="20,0,0,0"
                                EmptyContent=""
                                MinWidth="30">
    <telerikChart:RadCartesianChart.Behaviors>
        <telerikChart:ChartPanAndZoomBehavior HandleDoubleTap="False"
                                              PanMode="None"
                                              ZoomMode="None" />
    </telerikChart:RadCartesianChart.Behaviors>
 
    <telerikChart:RadCartesianChart.VerticalAxis>
        <telerikChart:LinearAxis LineStroke="{StaticResource PhoneDisabledBrush}"
                                 LineThickness="0"
                                 Maximum="34.7725"
                                 Minimum="34.36"
                                 Visibility="Collapsed" />
    </telerikChart:RadCartesianChart.VerticalAxis>
 
    <telerikChart:RadCartesianChart.HorizontalAxis>
        <telerikChart:CategoricalAxis LineStroke="{StaticResource PhoneDisabledBrush}"
                                      LineThickness="0"
                                      Visibility="Collapsed" />
    </telerikChart:RadCartesianChart.HorizontalAxis>
 
    <telerikChart:CandlestickSeries>
        <telerikCharting:OhlcDataPoint Category="Mon"
                                       Open="34.48"
                                       High="34.69"
                                       Low="34.47"
                                       Close="34.63"/>
    </telerikChart:CandlestickSeries>
</telerikChart:RadCartesianChart>

My C# code:

private void DisplayOhlcValue(DateTime dtTime, float fOpen, float fHigh, float fLow, float fClose)
{
    // Plot the candlelight
    CandlestickSeries ohlcSeries = (CandlestickSeries)rccPerformanceOHLC.Series[0];
 
    float min = fLow - ((fHigh - fLow) / 2f);
    float max = min + ((fHigh - min) / 0.8f);
 
    ((LinearAxis)rccPerformanceOHLC.VerticalAxis).Maximum = max;
    ((LinearAxis)rccPerformanceOHLC.VerticalAxis).Minimum = min;
 
    // 1. Code that clears the existing data point and adds a new one
    //ohlcSeries.DataPoints.Clear();
    //ohlcSeries.DataPoints.Add(new OhlcDataPoint());
    //ohlcSeries.DataPoints[0].Category = "";
    //ohlcSeries.DataPoints[0].Open = fOpen;
    //ohlcSeries.DataPoints[0].High = fHigh;
    //ohlcSeries.DataPoints[0].Low = fLow;
    //ohlcSeries.DataPoints[0].Close = fClose;
 
    // 2. Code that changes OHLC values in the existing data point
    //((OhlcDataPoint)ohlcSeries.DataPoints[0]).Category = "";
    //((OhlcDataPoint)ohlcSeries.DataPoints[0]).Open = fOpen;
    //((OhlcDataPoint)ohlcSeries.DataPoints[0]).High = fHigh;
    //((OhlcDataPoint)ohlcSeries.DataPoints[0]).Low = fLow;
    //((OhlcDataPoint)ohlcSeries.DataPoints[0]).Close = fClose;
}

I tried two ways to set OHLC values, as seen in the code. But I get an Index out of range error for both. What am I doing wrong?

1 Answer, 1 is accepted

Sort by
0
Shantimohan
Top achievements
Rank 1
answered on 30 Oct 2012, 02:49 AM
Sorry, I found the error while debugging another thing. It was my bad. The fOpen value passed was 0. After calculating correct fOpen, it is not giving any error.

You can close the thread.
Tags
Chart
Asked by
Shantimohan
Top achievements
Rank 1
Answers by
Shantimohan
Top achievements
Rank 1
Share this question
or