Index error when setting OHLC Data Point

2 posts, 0 answers
  1. Shantimohan
    Shantimohan avatar
    42 posts
    Member since:
    Jul 2012

    Posted 29 Oct 2012 Link to this post

    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?

  2. Shantimohan
    Shantimohan avatar
    42 posts
    Member since:
    Jul 2012

    Posted 29 Oct 2012 Link to this post

    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.
  3. DevCraft banner
Back to Top