Help on updating Legend Labels

4 posts, 0 answers
  1. Ivy
    Ivy avatar
    8 posts
    Member since:
    Oct 2009

    Posted 17 Dec 2009 Link to this post

    hi,

    I am currently implementing grouping/aggregate function using RadChart.  But I am doing mulitiple SeriesMapping at the same time.  The legend is automatically generating labels however... I need a way to modify the labels so that it could be used to identify which SeriesMapping and grouping at the same time.

    Example:

    Grouped by "Title"
    Mapping of 3 datasets

    Legend should look like:
    Title 1 DataSet 1
    Title 2 DataSet 1
    Title 1 DataSet 2
    Title 2 DataSet 2
    Title 1 DataSet 3
    Title 2 DataSet 3

    But the smart legend is dong just this:
    Title 1
    Title 2
    Title 1
    Title 2
    Title 1
    Title 2






     

    public void BindChart(string aggregateFunction, GroupDescriptorCollection gridGroupDescriptors, object gridItemsSource, string[] dataSets)

     

    {

    RadChart1.DefaultView.ChartArea.AdditionalYAxes.Clear();

    RadChart1.ItemsSource = Translate(gridItemsSource);

    RadChart1.SeriesMappings.Clear();

     

    ChartAggregateFunction aggFunct = (ChartAggregateFunction)Enum.Parse(typeof(ChartAggregateFunction), aggregateFunction, true);

     

     

    foreach (string dataSet in dataSets)

     

    {

     

    SeriesMapping mapping = new SeriesMapping();

     

    mapping.ItemMappings.Clear();

    mapping.ItemMappings.Add(

    new ItemMapping(dataSet, DataPointMember.YValue, aggFunct));

     

     

    mapping.SeriesDefinition =

    new BarSeriesDefinition();

     

    #region

     

    Assign Axis Y

     

     

    //if (RadChart1.SeriesMappings.Count > 1)

     

     

    //{

     

     

    // RadChart1.DefaultView.ChartArea.AdditionalYAxes.Add(GenerateYAxis(dataSet));

     

     

    // mapping.SeriesDefinition.AxisName = dataSet;

     

     

    //}

     

    #endregion

     

    ChartGroupDescriptorCollection chartGroupDescriptors = new ChartGroupDescriptorCollection();

     

     

    foreach (GroupDescriptor descriptor in gridGroupDescriptors)

     

    mapping.GroupingSettings.GroupDescriptors.Add(

    new ChartGroupDescriptor(descriptor.Member, descriptor.MemberType));

     

     

    GroupDescriptor lastGroupDescriptor;

     

     

    if (gridGroupDescriptors.Count > 0 && aggregateFunction.ToLower() != "none")

     

    {

    lastGroupDescriptor = gridGroupDescriptors[gridGroupDescriptors.Count - 1];

    mapping.ItemMappings.Add(

    new ItemMapping(lastGroupDescriptor.Member, DataPointMember.XCategory));

     

    }

    RadChart1.SeriesMappings.Add(mapping);

    }

    }

  2. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 22 Dec 2009 Link to this post

    Hi,

    RadChart will do this automatically for you. I believe you have already found the corresponding online example. In addition, I have attached a simplified version with 2 SeriesMapping objects.

    Kind regards,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Ivy
    Ivy avatar
    8 posts
    Member since:
    Oct 2009

    Posted 22 Dec 2009 Link to this post

    Thank you for your reply.  But I believe I am already doing this multiple series mappings.  The chart is correctly graphing as I programmed with several mappings.  But I am not happy with the automatic legend created as I grouped and I want to tweak it to my liking.  Is that possible?  How can I access the automatic legend and perhaps append something to it?
  4. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 23 Dec 2009 Link to this post

    Hello,

    Let me start with my apologies -- it seems I have attached an example which is somewhat erroneous - adding the same mappings twice. I have attached the correct version now. Note, that there is only one series mapping and the legend items contain information for both - region and year.

    As for updating the legend items directly - you can wire the DataBound event of RadChart and loop through the data series (RadChart1.DefaultView.ChartArea.DataSeries). You can modify each DataSeries object's LegendLabel property - the change will be reflected in the legend immediately:

    RadChart1.DefaultView.ChartArea.DataSeries[0].LegendLabel = "My Label"

    Best regards,
    Ves
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top