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

dynamic legend series in a graph

3 Answers 204 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bryan Doan
Top achievements
Rank 1
Bryan Doan asked on 30 Aug 2010, 12:42 PM
Hello,

I'm trying to have the serie names in my legend dynamically changed based on users's select.  There are three series in my graph and these series are based on the years that users select from filters.  For example, if users select 2008, 2009, and 2010, the three series will show data for these three years and the legend will show these three years.  So if users select three different years, the legend will show three different years.  Can I do that?

Thanks!

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 01 Sep 2010, 03:04 PM
Hello Bryan Doan,

To change dynamically the chart's legend items you have to create LabelItems and add them to the legend items collection as shown in the following code snippet: 

Telerik.Reporting.Charting.LabelItem labelItem1 = new Telerik.Reporting.Charting.LabelItem();
Telerik.Reporting.Charting.LabelItem labelItem2 = new Telerik.Reporting.Charting.LabelItem();
labelItem1.Marker.Visible = true;
labelItem1.TextBlock.Text = "2008";
labelItem2.Marker.Visible = true;
labelItem2.TextBlock.Text = "2009";
chart1.Legend.Items.AddRange(new Telerik.Reporting.Charting.LabelItem[] {labelItem1,labelItem2});

To create a customizable Chart please check out the Creating Chart Programmatically - more complex example help article.

Best wishes,
Peter
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Bryan Doan
Top achievements
Rank 1
answered on 03 Sep 2010, 09:09 AM

Hi Peter,

Thank you so much for your help, but is there anyway not having to hardcode "2008" and "2009" for the legends?  I need this to be dynamically changed base on the years that users select for the graphs.

 

Thanks!

 

-Bryan

0
Peter
Telerik team
answered on 07 Sep 2010, 04:53 PM
Hi Bryan Doan,

If you want to change the Legend dynamically you will have to create the whole chart programmatically within a report event. For more information check out the Creating Chart Programmatically - more complex example help article.

How to access the report parameters selected value from the Event's processing item is shown in the following code snippet:
Copy Code
var myVal = procChart.Report.Parameters["Parameter1"].Value;
  
Best wishes,
Peter
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Bryan Doan
Top achievements
Rank 1
Answers by
Peter
Telerik team
Bryan Doan
Top achievements
Rank 1
Share this question
or