Data Binding into a RadChart

5 posts, 0 answers
  1. Robert Smallwood
    Robert Smallwood avatar
    12 posts
    Member since:
    Jul 2009

    Posted 04 Sep 2009 Link to this post

    Does anyone have any examples of how they have used databinding to retrieve data from the MS SQL database and fed it into a Rad Chart?

    I'm able to do all kinds of cool things with static data in code with the Rad Charts. I'm also able to successfully do data binding per the Telerik TV tutorials with binding a simple SQL database to a GridView via a LINQ-SQL class and WCF.

    Most of the data binding videos and tutorials available show how to query a database and return the results via Linq-Sql/WCF web services to a gridview but nothing about how to limit the fields returned or get a string of values from a SQL database and populate a chart with the results.

    If anyone can provide any help at all it would be greatly appreciated.

    Robert
  2. Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 07 Sep 2009 Link to this post

    Hello Robert,

    There is an example that demonstrates binding RadChart to ADO.NET Data Service here: http://demos.telerik.com/silverlight/#Chart/DataBinding. You can check the example code files in your local installation to see how the chart is bound to the service result.


    Regards,
    Bart.
  3. Robert Smallwood
    Robert Smallwood avatar
    12 posts
    Member since:
    Jul 2009

    Posted 08 Sep 2009 Link to this post

    The databinding example provided is probably a bit more complex than what I'm trying to accomplish. I apologize for asking this question in such a way but I'm very new to both C# and the Telerik product.

    What I currently have is a test project with an extremely simple "Employee" database containing the following:

    EmployeeID                Primary key, incremented number starting from 1
    EmployeeName          Random first name
    EmployeeAge            Random Age

    I've populated the table with about 8 entries.

    Following the WCF databinding to Radgridview tutorial on Telerik TV I've performed the following:
    1. Created a new project
    2. Created a new LINQ to SQL class and named it
    3. Dragged the "Employee" database to the design surface
    4. Created a new WCF Service and named it (I've also accomplished the same results using a "Silverlight-Enabled WCF Service").
    5. I've added my basic query code to my dataservice as follows:
    5a.   Public List<EMPLOYEE> GetEmpAge()
            {
             MyDataContext db = new MyDataContext();
             var query = (from emp in db.Employee select emp);
            return query.ToList();
            }
    6. I've added my service request to the client app.
    7. I've bound the data to a Radgridview with a button eventhandler as follows:
    7a    private void Button_Click(object sender, RoutedEventArgs e)
            {
                ServiceReference1.ALCDataServiceClient client = new TestSite2.ServiceReference1.ALCDataServiceClient();
                client.GetEmpAgeCompleted += new EventHandler<TestSite2.ServiceReference1.GetEmpAgeCompletedEventArgs>(client_GetEmpAgeCompleted);
                client.GetEmpAgeAsync();
            }

            void client_GetEmpAgeCompleted(object sender, TestSite2.ServiceReference1.GetEmpAgeCompletedEventArgs e)
            {
                datagrid.ItemsSource = e.Result;
            }

    All of which works fantastic. Now what I need to do is either limit the columns returned through my query, return the entire result and store it, or when the result is returned feed the EmployeeAge results into a variable that I can use later to feed into various Rad charts as I need to.

    I'm unsure how to proceed from here. Most of the tutorials I can find assume a higher level of familiarity with C# than I currently have.

    Again, any help, suggestions or simple samples would be greatly appreciated.

    Robert
  4. Robert Smallwood
    Robert Smallwood avatar
    12 posts
    Member since:
    Jul 2009

    Posted 10 Sep 2009 Link to this post

    Bart,

    I went back and spent some time going over the examples provided in your demo application and have played around using ADO instead of WCF to bind the data to my chart.

    I've had a lot of success with this method and the results are great. The one problem I've run into now is that one field in my database which contains the numeric data I need to chart is stored as a string (The database was created automatically by another vendors software platform for storing trended data).

    I'm using the following to set up my chart:

     

    private void ATOMRequestCompleted(IAsyncResult asyncResult)

     

    {

     

    DataServiceQuery<TRENDDATA> trendquery = (DataServiceQuery<TRENDDATA>)asyncResult.AsyncState;

     

     

    SeriesMapping seriesMapping = new SeriesMapping();

     

    seriesMapping.SeriesDefinition =

    new LineSeriesDefinition();

     

     

    ItemMapping itemMapping = new ItemMapping("DATA_VALUE_", DataPointMember.YValue);

     

    seriesMapping.ItemMappings.Add(itemMapping);

    chart1.SeriesMappings.Add(seriesMapping);

     

    List<TRENDDATA> list = trendquery.EndExecute(asyncResult).ToList();

     

     

    chart1.ItemsSource = list;

    }


    Is there a way to make the RadChart accept the returned numeric strings or am I going to need to add a routine to take the result of the query and convert each string into an integer?

    Thanks!
  5. Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 11 Sep 2009 Link to this post

    Hello Robert,

    I don't believe RadChart supports such conversion out-of-the-box -- the control works with numerical data and I believe you will need to write a custom routine to process the string data manually.


    Greetings,
    Bart.
Back to Top