RadHtmlChart - How databind chart data at the server side?

6 posts, 0 answers
  1. Sudipta
    Sudipta avatar
    6 posts
    Member since:
    May 2014

    Posted 18 May 2014 Link to this post

    Hi,

    I am using a telerik:RadRotator which rotates a bunch of RadHtmlChart (s) that show sales performance graphs in a slow rotating fashion. I am able to bind data at the server side to the RadRotator. I was able to find control for each individual RadHtmlChart. But the issue is that I am unable to extract the data item from the NamingContainer. Any help will be highly appreciated. Thanks in Advance.

    Code block I am using is below.

    Thanks,
    Sudipta

    protected void Page_Load(object sender, EventArgs e)
    {
        var summary = new SalesReports().GetSalesRepresentativeSummary();
        this.RadRotator.DataSource = summary;
        this.RadRotator.DataBind();
    }
     
    protected void RadRotator_ItemDataBound(object sender, RadRotatorEventArgs e)
    {
        try
        {
            SalesRepresentativeSummary salesRepresentativeSummary = (SalesRepresentativeSummary)e.Item.DataItem;
     
            if (salesRepresentativeSummary != null)
            {
                // Populate sub section repeater
                RadHtmlChart SalesRepPerformanceRadHtmlChart = (RadHtmlChart)e.Item.FindControl("SalesRepPerformanceRadHtmlChart");
                if (SalesRepPerformanceRadHtmlChart != null)
                {
                    SalesRepPerformanceRadHtmlChart.DataBinding += new EventHandler(SalesRepPerformanceRadHtmlChart_DataBinding);
     
                    // Show only active ones
                    SalesRepPerformanceRadHtmlChart.DataSource = new List<SalesRepresentativeSummary> { salesRepresentativeSummary };
                    SalesRepPerformanceRadHtmlChart.DataBind();
                }
            }
     
        }
        catch (Exception ex)
        {
        }
    }
     
    protected void SalesRepPerformanceRadHtmlChart_DataBinding(object sender, EventArgs e)
    {
        try
        {
            RadHtmlChart SalesRepPerformanceRadHtmlChart = (RadHtmlChart)sender;
     
            if (SalesRepPerformanceRadHtmlChart != null)
            {
    // I need to find the IList<SalesRepresentativeSummary> and bind to the chart 
                IList<SalesRepresentativeSummary> dataItem = (List<SalesRepresentativeSummary>)SalesRepPerformanceRadHtmlChart.NamingContainer;
     
                SalesRepPerformanceRadHtmlChart.ChartTitle.Text = "Hello" + " - It works";
            }
     
        }
        catch (Exception ex)
        {
        }
    }
  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 21 May 2014 Link to this post

    Hello Sudipta,

    If you want to extract the data for the e.Item.DataItem argument of the Rotator's ItemDataBound event you must cast it to a DataRowView. For example:
    string currText = (e.Item.DataItem as DataRowView).Row[1].ToString();
    decimal currValue = decimal.Parse((e.Item.DataItem as DataRowView).Row[2].ToString());

    You can find the full runnable VS example on this regard in the attached archive.

    Regards,
    Danail Vasilev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sudipta
    Sudipta avatar
    6 posts
    Member since:
    May 2014

    Posted 21 May 2014 in reply to Danail Vasilev Link to this post

    Danail,

    Thanks for your response. I was able to get the parent data item by using the naming container. Here goes the lines of code:

    RadRotatorItem rotatorItem = (RadRotatorItem)SalesRepPerformanceRadHtmlChart.NamingContainer;
    SalesRepresentativeSummary salesRepresentativeSummary = (SalesRepresentativeSummary)rotatorItem.DataItem;

    Thanks,
    Sudipta
  5. Manu
    Manu avatar
    24 posts
    Member since:
    Aug 2015

    Posted 25 Aug 2015 Link to this post

    Hi,

    Greetings!

    I am new to telerik, I have created some RadHtmlCharts. those are looking and working pretty good. but now I want them in a radRotator. I seen some of the posts, but I dint get how to start. please give me demo. my charts designed by getting data from db. so please show me both aspx and aspx.cs. thanks in advance.

    thanks,

    Manu

  6. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 26 Aug 2015 Link to this post

    Hi Manu,

    You can find such an example in the attachment from my previous post - http://screencast.com/t/L11a8S3q

    For you convenience I have pasted it the link below:

    http://www.telerik.com/clientsfiles/0591c7a0-86b2-460e-b7bb-e517acbb373b_RadRotator-RadHtmlChart.zip?sfvrsn=0

    Regards,
    Danail Vasilev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Manu
    Manu avatar
    24 posts
    Member since:
    Aug 2015

    Posted 27 Aug 2015 in reply to Danail Vasilev Link to this post

    thanks a lot for your reply!!

    i tried it.. its working fine. :)

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017