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

Databinding RadChart to a DataView

2 Answers 118 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 03 Jun 2008, 03:51 AM
Hello,

I'm working with a page that has a RadGrid and a RadChart that I want to tie to the same dataview so when I apply a filter to the dataview it is reflected on both the grid and the chart.

I'm having no trouble binding the view to the grid and using the Property Builder to format it.  But when I try to basically duplicate the process with the chart I'm getting an error creating the series.

The page load event loads the dataview like this (ignore the fact the the RadGrid references are missing, this is just a copy of the code for testing)...

private void LoadDataView()  
    {  
        SqlConnection myConn = new SqlConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);  
        SqlDataAdapter da = new SqlDataAdapter();  
        DataSet ds = new DataSet();  
 
        try  
        {  
            myConn.Open();  
            da.SelectCommand = new SqlCommand("select *, DateDiff(d,TimeStamp,GetDate()) as DaysOld, DateDiff(m,TimeStamp,GetDate()) as MonthsOld,RANK() OVER (order by TIMESTAMP) as RowNumber from ReadHistory where CardID = 'ABC00002' order by TimeStamp", myConn);  
            da.Fill(ds, "ReadData");  
            DataView dv = ds.Tables["ReadData"].DefaultView;  
            Session["ReadData"] = dv;  
            RadChart2.DataSource = dv;  
            RadChart2.Series[0].DataYColumn = "Systolic";  
            RadChart2.DataBind();  
        }  
        catch (Exception ex)  
        {  
            MessageBox.Show("Error Loading Data: " + ex.Message.ToString());  
        }  
    } 

The RadChart2.Series[0].DataYColumn = "Systolic" line is thowing the error: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index."

Is what I'm attempting to accomplish possible? (eg - 1 data view used by both objects?)

Any ideas?

Thanks in advance,
Rick


2 Answers, 1 is accepted

Sort by
0
Bartholomeo Rocca
Top achievements
Rank 1
answered on 03 Jun 2008, 06:55 AM
Hello Rick,

It seems the Series collection is empty and that causes the OutOfRangeException you are experiencing. Could you check whether you have a series instance in the ASPX declaration of the chart control? Alternatively, you can create one from code-behind and add it to the Series collection as well.


Greetings,
Bart.
0
Rick
Top achievements
Rank 1
answered on 03 Jun 2008, 05:32 PM
Grrr, I'd missed the obvious....

Thanks,
Rick
Tags
Chart (Obsolete)
Asked by
Rick
Top achievements
Rank 1
Answers by
Bartholomeo Rocca
Top achievements
Rank 1
Rick
Top achievements
Rank 1
Share this question
or