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

RadHtmlChart - How databind chart data at the server side?

5 Answers 211 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Sudipta
Top achievements
Rank 1
Sudipta asked on 19 May 2014, 12:50 AM
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)
    {
    }
}

5 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 21 May 2014, 07:00 AM
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.

 
0
Sudipta
Top achievements
Rank 1
answered on 21 May 2014, 11:34 PM
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
0
Bhavya
Top achievements
Rank 1
answered on 25 Aug 2015, 06:58 AM

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

0
Danail Vasilev
Telerik team
answered on 26 Aug 2015, 03:09 PM
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
0
Bhavya
Top achievements
Rank 1
answered on 27 Aug 2015, 06:21 AM

thanks a lot for your reply!!

i tried it.. its working fine. :)

 

Tags
Chart (HTML5)
Asked by
Sudipta
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Sudipta
Top achievements
Rank 1
Bhavya
Top achievements
Rank 1
Share this question
or