dynamic legend series in a graph

4 posts, 0 answers
  1. Bryan Doan
    Bryan Doan avatar
    14 posts
    Member since:
    May 2010

    Posted 30 Aug 2010 Link to this post

    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!

  2. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 01 Sep 2010 Link to this post

    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
  3. DevCraft banner
  4. Bryan Doan
    Bryan Doan avatar
    14 posts
    Member since:
    May 2010

    Posted 03 Sep 2010 Link to this post

    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

  5. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 07 Sep 2010 Link to this post

    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
Back to Top