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

Setting up Chart Type at runtime in Code Behind

3 Answers 239 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
h@r!
Top achievements
Rank 1
h@r! asked on 30 Nov 2010, 11:34 AM
Hi,

I am using RadChart as user control and need to use the control to load different Chart Types.I am able to load the Chart Types but unable to display them as loaded.

<telerik:RadChart ID="rcTrendGraph" runat="server"></telerik:RadChart>

this is my aspx page and in the code behind I am using the following code to Build the Graph.

for (int i = 0; i < strContentIds.Length; i++){
strDashContId = strContentIds[i].ToString();
if (strDashContId == "TGI1002"){
//Bar Graph
rcTrendGraph.ChartTitle.TextBlock.Text = "Bar Graph";
rcTrendGraph.ChartTitle.Appearance.Position.AlignedPosition=Telerik.Charting.Styles.AlignedPositions.Top;
rcTrendGraph.AddChartSeries(legend);
legend.Type = Telerik.Charting.ChartSeriesType.Bar;
rcTrendGraph.DataSource =ds;
rcTrendGraph.DataBind();
}
else if (strDashContId == "TGI1003"){
//Pie Graph
rcTrendGraph.ChartTitle.TextBlock.Text = "Pie Graph";
rcTrendGraph.ChartTitle.Appearance.Position.AlignedPosition=Telerik.Charting.Styles.AlignedPositions.Top;
rcTrendGraph.AddChartSeries(legend);
legend.Type = Telerik.Charting.ChartSeriesType.Pie;
legend.AddItem(10,"A");
legend.AddItem(20,"B");
legend.AddItem(30,"C");
legend.AddItem(40,"D");
}
else if (strDashContId == "TGI1001")
{//Line Graph
rcTrendGraph.ChartTitle.TextBlock.Text = "Line Graph";
rcTrendGraph.ChartTitle.Appearance.Position.AlignedPosition=Telerik.Charting.Styles.AlignedPositions.Top;
rcTrendGraph.AddChartSeries(legend);
legend.Type = Telerik.Charting.ChartSeriesType.Line;
legend.AddItem(10,"A");
legend.AddItem(20,"B");
legend.AddItem(30,"C");
legend.AddItem(40,"D");
}
}

I am able to get the chart generated but getting the same chart type at the end..
For Suppose strContentIds.Length=2
and for i=0 strDashContId =TGI1001
and for i=1 strDashContId =TGI1003
I need the chart as pie Graph and Line Graph to be displayed in my page.But I am able to dispaly only one of the chart type i.e, for strDashContId =TGI1003 and strDashContId =TGI1001 I am getting Pie as strContentIds[1]=TGI1003  after strDashContId =TGI1001 and getting both the charts as Pie Charts only.

Please help me out with your suggestions.

Thanks In Advance,
h@r!

3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 02 Dec 2010, 03:07 PM
Hello,

I am afraid I was not able to follow your scenario completely. Looking at the code I can see a ChartSeries object, whose type is updated for each entry in strContentIds. So, its type will always correspond to the last entry in strContentIds. I can only guess, but if you have multiple instances of that user control and each one gets the same array -- all the charts will have series of type, which is applicable for the last entry in the array. If that is the case -- you may consider sending a single string to each user control to define the series type. However, if I am wrong please, provide more details about the specific implementation. You can open a formal support ticket and attached a small runnable sample, which shows the issue, so we can review it and get back to you with our findings.

Best regards,
Ves
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
h@r!
Top achievements
Rank 1
answered on 03 Dec 2010, 07:00 AM
Hi Vas,

Thanks for your Reply!
You followed my scenario perfectly. I am using a single object for multiple times with different data loaded.As I cannot create multiple objects for that user control and I need to show that user control multiple times with different data loaded into my home page I just followed the code that I posted previously.

I can explain the scenario clearly:

From my home page I am calling a query and getting the path of the user controls that are to be loaded and calling the LoadWidget() method as follows.

private void LoadWidget(RadDock dock)
{
 if (string.IsNullOrEmpty(dock.Tag))
{
return;
}
Control widget = LoadControl(dock.Tag);
dock.ContentContainer.Controls.Add(widget);
}

In my .aspx file I am using the:RadDockLayout as follows which are loaded dynamically from my query based on a particular value.:

<telerik:RadDockLayout runat="server" ID="RadDockLayout1" EnableEmbeddedSkins="false" Skin="None">
<div id="maincontainer">
<div id="contentwrapper">
<div id="Secondcolumn">
<telerik:RadDockZone runat="server" Style="border: 0px;" ID="RadDockZone2" Orientation="Vertical" Width="100%">
</telerik:RadDockZone>
</div>
</div>
<div id="Firstcolumn">
<telerik:RadDockZone runat="server" Style="border: 0px;" ID="RadDockZone1" Orientation="Vertical" MinHeight="300px" Width="100%">
</telerik:RadDockZone>
</div>
<div id="Thirdcolumn">
<telerik:RadDockZone runat="server" Style="border: 0px;" ID="RadDockZone3" Orientation="Vertical" Width="100%">
</telerik:RadDockZone>
</div>
</div>
</telerik:RadDockLayout>


After loading the Widgets the User controls are being loaded.
So if I get the same user control path for multiple times then the same user control is called for multiple times with different data.As the home page is loaded, finally I am getting same data in all the widgets in different docks that called the same user control.Here  after the LoadWidget() method is called the user controls are being called.So I need to make LoadWidget() in such a way that from the LoadWidget() it need to go to userocntrol and bind it to widget then come back to home page get the next value and call the LoadWidget() and again bind that to home page.So that I can have different data loaded.

Hope I tried to explain you clearly.As I can't post the entire code I explained the scenario in detail.

Thanks,
h@r!
0
Ves
Telerik team
answered on 07 Dec 2010, 05:56 PM
Hi,

If my guess has been correct then it seems you need to revise the logic which determines the chart type. Let me get back to the procedural code from your initial post. The type of the ChartSeries is defined by the last entry in the strContentIds array. No matter how many item it contains, the chart series type is defined by the last one as it is always the same chart that is updated within the loop. I understand you might not be able to post the entire project, but still, you can try to isolate the problem in a small stand-alone project. Just a single page and a user control, loaded twice, using fake data and strings for strContentIds. This way it would be easier for you to debug it and see which chart is updated and when.

Best regards,
Ves
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Chart (Obsolete)
Asked by
h@r!
Top achievements
Rank 1
Answers by
Ves
Telerik team
h@r!
Top achievements
Rank 1
Share this question
or